@@ -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) ; 
@@ -703,45 +682,17 @@ pub(super) fn type_param_predicates(
703682    let  mut  extend = None ; 
704683
705684    let  item_hir_id = tcx. local_def_id_to_hir_id ( item_def_id) ; 
706-     let  ast_generics = match  tcx. hir_node ( item_hir_id)  { 
707-         Node :: TraitItem ( item)  => item. generics , 
708- 
709-         Node :: ImplItem ( item)  => item. generics , 
710- 
711-         Node :: Item ( item)  => { 
712-             match  item. kind  { 
713-                 ItemKind :: Fn ( ..,  generics,  _) 
714-                 | ItemKind :: Impl ( & hir:: Impl  {  generics,  .. } ) 
715-                 | ItemKind :: TyAlias ( _,  generics) 
716-                 | ItemKind :: Const ( _,  generics,  _) 
717-                 | ItemKind :: OpaqueTy ( & OpaqueTy  { 
718-                     generics, 
719-                     origin :  hir:: OpaqueTyOrigin :: TyAlias  {  .. } , 
720-                     ..
721-                 } ) 
722-                 | ItemKind :: Enum ( _,  generics) 
723-                 | ItemKind :: Struct ( _,  generics) 
724-                 | ItemKind :: Union ( _,  generics)  => generics, 
725-                 ItemKind :: Trait ( _,  _,  generics,  ..)  => { 
726-                     // Implied `Self: Trait` and supertrait bounds. 
727-                     if  param_id == item_hir_id { 
728-                         let  identity_trait_ref =
729-                             ty:: TraitRef :: identity ( tcx,  item_def_id. to_def_id ( ) ) ; 
730-                         extend = Some ( ( identity_trait_ref. to_predicate ( tcx) ,  item. span ) ) ; 
731-                     } 
732-                     generics
733-                 } 
734-                 _ => return  result, 
735-             } 
736-         } 
737- 
738-         Node :: ForeignItem ( item)  => match  item. kind  { 
739-             ForeignItemKind :: Fn ( _,  _,  generics)  => generics, 
740-             _ => return  result, 
741-         } , 
742685
743-         _ => return  result, 
744-     } ; 
686+     let  hir_node = tcx. hir_node ( item_hir_id) ; 
687+     let  Some ( ast_generics)  = hir_node. generics ( )  else  {  return  result } ; 
688+     if  let  Node :: Item ( item)  = hir_node
689+         && let  ItemKind :: Trait ( ..)  = item. kind 
690+         // Implied `Self: Trait` and supertrait bounds. 
691+         && param_id == item_hir_id
692+     { 
693+         let  identity_trait_ref = ty:: TraitRef :: identity ( tcx,  item_def_id. to_def_id ( ) ) ; 
694+         extend = Some ( ( identity_trait_ref. to_predicate ( tcx) ,  item. span ) ) ; 
695+     } 
745696
746697    let  icx = ItemCtxt :: new ( tcx,  item_def_id) ; 
747698    let  extra_predicates = extend. into_iter ( ) . chain ( 
0 commit comments