@@ -123,43 +123,22 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
123123 // Preserving the order of insertion is important here so as not to break UI tests.
124124 let mut predicates: FxIndexSet < ( ty:: Clause < ' _ > , Span ) > = FxIndexSet :: default ( ) ;
125125
126- let ast_generics = match node {
127- Node :: TraitItem ( item) => item. generics ,
128-
129- Node :: ImplItem ( item) => item. generics ,
130-
131- Node :: Item ( item) => match item. kind {
126+ let ast_generics = node. generics ( ) . unwrap_or ( NO_GENERICS ) ;
127+ if let Node :: Item ( item) = node {
128+ match item. kind {
132129 ItemKind :: Impl ( impl_) => {
133130 if impl_. defaultness . is_default ( ) {
134131 is_default_impl_trait = tcx
135132 . impl_trait_ref ( def_id)
136133 . map ( |t| ty:: Binder :: dummy ( t. instantiate_identity ( ) ) ) ;
137134 }
138- impl_. generics
139135 }
140- ItemKind :: Fn ( .., generics, _)
141- | ItemKind :: TyAlias ( _, generics)
142- | ItemKind :: Const ( _, generics, _)
143- | ItemKind :: Enum ( _, generics)
144- | ItemKind :: Struct ( _, generics)
145- | ItemKind :: Union ( _, generics) => generics,
146-
147- ItemKind :: Trait ( _, _, generics, self_bounds, ..)
148- | ItemKind :: TraitAlias ( generics, self_bounds) => {
136+
137+ ItemKind :: Trait ( _, _, _, self_bounds, ..) | ItemKind :: TraitAlias ( _, self_bounds) => {
149138 is_trait = Some ( self_bounds) ;
150- generics
151139 }
152- ItemKind :: OpaqueTy ( OpaqueTy { generics, .. } ) => generics,
153- _ => NO_GENERICS ,
154- } ,
155-
156- Node :: ForeignItem ( item) => match item. kind {
157- ForeignItemKind :: Static ( ..) => NO_GENERICS ,
158- ForeignItemKind :: Fn ( _, _, generics) => generics,
159- ForeignItemKind :: Type => NO_GENERICS ,
160- } ,
161-
162- _ => NO_GENERICS ,
140+ _ => { }
141+ }
163142 } ;
164143
165144 let generics = tcx. generics_of ( def_id) ;
@@ -705,45 +684,17 @@ pub(super) fn type_param_predicates(
705684 let mut extend = None ;
706685
707686 let item_hir_id = tcx. local_def_id_to_hir_id ( item_def_id) ;
708- let ast_generics = match tcx. hir_node ( item_hir_id) {
709- Node :: TraitItem ( item) => item. generics ,
710-
711- Node :: ImplItem ( item) => item. generics ,
712-
713- Node :: Item ( item) => {
714- match item. kind {
715- ItemKind :: Fn ( .., generics, _)
716- | ItemKind :: Impl ( & hir:: Impl { generics, .. } )
717- | ItemKind :: TyAlias ( _, generics)
718- | ItemKind :: Const ( _, generics, _)
719- | ItemKind :: OpaqueTy ( & OpaqueTy {
720- generics,
721- origin : hir:: OpaqueTyOrigin :: TyAlias { .. } ,
722- ..
723- } )
724- | ItemKind :: Enum ( _, generics)
725- | ItemKind :: Struct ( _, generics)
726- | ItemKind :: Union ( _, generics) => generics,
727- ItemKind :: Trait ( _, _, generics, ..) => {
728- // Implied `Self: Trait` and supertrait bounds.
729- if param_id == item_hir_id {
730- let identity_trait_ref =
731- ty:: TraitRef :: identity ( tcx, item_def_id. to_def_id ( ) ) ;
732- extend = Some ( ( identity_trait_ref. to_predicate ( tcx) , item. span ) ) ;
733- }
734- generics
735- }
736- _ => return result,
737- }
738- }
739-
740- Node :: ForeignItem ( item) => match item. kind {
741- ForeignItemKind :: Fn ( _, _, generics) => generics,
742- _ => return result,
743- } ,
744687
745- _ => return result,
746- } ;
688+ let hir_node = tcx. hir_node ( item_hir_id) ;
689+ let Some ( ast_generics) = hir_node. generics ( ) else { return result } ;
690+ if let Node :: Item ( item) = hir_node
691+ && let ItemKind :: Trait ( ..) = item. kind
692+ // Implied `Self: Trait` and supertrait bounds.
693+ && param_id == item_hir_id
694+ {
695+ let identity_trait_ref = ty:: TraitRef :: identity ( tcx, item_def_id. to_def_id ( ) ) ;
696+ extend = Some ( ( identity_trait_ref. to_predicate ( tcx) , item. span ) ) ;
697+ }
747698
748699 let icx = ItemCtxt :: new ( tcx, item_def_id) ;
749700 let extra_predicates = extend. into_iter ( ) . chain (
0 commit comments