@@ -181,7 +181,7 @@ pub(crate) enum RibKind<'a> {
181181 FnOrCoroutine ,
182182
183183 /// We passed through an item scope. Disallow upvars.
184- Item ( HasGenericParams ) ,
184+ Item ( HasGenericParams , DefKind ) ,
185185
186186 /// We're in a constant item. Can't refer to dynamic stuff.
187187 ///
@@ -221,7 +221,7 @@ impl RibKind<'_> {
221221 | RibKind :: MacroDefinition ( _)
222222 | RibKind :: ConstParamTy
223223 | RibKind :: InlineAsmSym => false ,
224- RibKind :: AssocItem | RibKind :: Item ( _ ) | RibKind :: ForwardGenericParamBan => true ,
224+ RibKind :: AssocItem | RibKind :: Item ( .. ) | RibKind :: ForwardGenericParamBan => true ,
225225 }
226226 }
227227
@@ -866,11 +866,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
866866 }
867867 fn visit_foreign_item ( & mut self , foreign_item : & ' ast ForeignItem ) {
868868 self . resolve_doc_links ( & foreign_item. attrs , MaybeExported :: Ok ( foreign_item. id ) ) ;
869+ let def_kind = self . r . local_def_kind ( foreign_item. id ) ;
869870 match foreign_item. kind {
870871 ForeignItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
871872 self . with_generic_param_rib (
872873 & generics. params ,
873- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
874+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
874875 LifetimeRibKind :: Generics {
875876 binder : foreign_item. id ,
876877 kind : LifetimeBinderKind :: Item ,
@@ -882,7 +883,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
882883 ForeignItemKind :: Fn ( box Fn { ref generics, .. } ) => {
883884 self . with_generic_param_rib (
884885 & generics. params ,
885- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
886+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
886887 LifetimeRibKind :: Generics {
887888 binder : foreign_item. id ,
888889 kind : LifetimeBinderKind :: Function ,
@@ -892,7 +893,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
892893 ) ;
893894 }
894895 ForeignItemKind :: Static ( ..) => {
895- self . with_static_rib ( |this| {
896+ self . with_static_rib ( def_kind , |this| {
896897 visit:: walk_foreign_item ( this, foreign_item) ;
897898 } ) ;
898899 }
@@ -2268,10 +2269,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
22682269
22692270 fn resolve_adt ( & mut self , item : & ' ast Item , generics : & ' ast Generics ) {
22702271 debug ! ( "resolve_adt" ) ;
2272+ let kind = self . r . local_def_kind ( item. id ) ;
22712273 self . with_current_self_item ( item, |this| {
22722274 this. with_generic_param_rib (
22732275 & generics. params ,
2274- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2276+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , kind ) ,
22752277 LifetimeRibKind :: Generics {
22762278 binder : item. id ,
22772279 kind : LifetimeBinderKind :: Item ,
@@ -2345,11 +2347,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23452347 let name = item. ident . name ;
23462348 debug ! ( "(resolving item) resolving {} ({:?})" , name, item. kind) ;
23472349
2350+ let def_kind = self . r . local_def_kind ( item. id ) ;
23482351 match item. kind {
23492352 ItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
23502353 self . with_generic_param_rib (
23512354 & generics. params ,
2352- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2355+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
23532356 LifetimeRibKind :: Generics {
23542357 binder : item. id ,
23552358 kind : LifetimeBinderKind :: Item ,
@@ -2362,7 +2365,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23622365 ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
23632366 self . with_generic_param_rib (
23642367 & generics. params ,
2365- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2368+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
23662369 LifetimeRibKind :: Generics {
23672370 binder : item. id ,
23682371 kind : LifetimeBinderKind :: Function ,
@@ -2401,7 +2404,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24012404 // Create a new rib for the trait-wide type parameters.
24022405 self . with_generic_param_rib (
24032406 & generics. params ,
2404- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2407+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
24052408 LifetimeRibKind :: Generics {
24062409 binder : item. id ,
24072410 kind : LifetimeBinderKind :: Item ,
@@ -2422,7 +2425,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24222425 // Create a new rib for the trait-wide type parameters.
24232426 self . with_generic_param_rib (
24242427 & generics. params ,
2425- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2428+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
24262429 LifetimeRibKind :: Generics {
24272430 binder : item. id ,
24282431 kind : LifetimeBinderKind :: Item ,
@@ -2456,7 +2459,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24562459 }
24572460
24582461 ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2459- self . with_static_rib ( |this| {
2462+ self . with_static_rib ( def_kind , |this| {
24602463 this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
24612464 this. visit_ty ( ty) ;
24622465 } ) ;
@@ -2471,11 +2474,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24712474 ItemKind :: Const ( box ast:: ConstItem { ref generics, ref ty, ref expr, .. } ) => {
24722475 self . with_generic_param_rib (
24732476 & generics. params ,
2474- RibKind :: Item ( if self . r . tcx . features ( ) . generic_const_items {
2475- HasGenericParams :: Yes ( generics. span )
2476- } else {
2477- HasGenericParams :: No
2478- } ) ,
2477+ RibKind :: Item (
2478+ if self . r . tcx . features ( ) . generic_const_items {
2479+ HasGenericParams :: Yes ( generics. span )
2480+ } else {
2481+ HasGenericParams :: No
2482+ } ,
2483+ def_kind,
2484+ ) ,
24792485 LifetimeRibKind :: Generics {
24802486 binder : item. id ,
24812487 kind : LifetimeBinderKind :: ConstItem ,
@@ -2560,7 +2566,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
25602566 let mut add_bindings_for_ns = |ns| {
25612567 let parent_rib = self . ribs [ ns]
25622568 . iter ( )
2563- . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( _ ) ) )
2569+ . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( .. ) ) )
25642570 . expect ( "associated item outside of an item" ) ;
25652571 seen_bindings. extend ( parent_rib. bindings . keys ( ) . map ( |ident| ( * ident, ident. span ) ) ) ;
25662572 } ;
@@ -2695,8 +2701,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26952701 self . label_ribs . pop ( ) ;
26962702 }
26972703
2698- fn with_static_rib ( & mut self , f : impl FnOnce ( & mut Self ) ) {
2699- let kind = RibKind :: Item ( HasGenericParams :: No ) ;
2704+ fn with_static_rib ( & mut self , def_kind : DefKind , f : impl FnOnce ( & mut Self ) ) {
2705+ let kind = RibKind :: Item ( HasGenericParams :: No , def_kind ) ;
27002706 self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
27012707 }
27022708
@@ -2877,7 +2883,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28772883 // If applicable, create a rib for the type parameters.
28782884 self . with_generic_param_rib (
28792885 & generics. params ,
2880- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2886+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , self . r . local_def_kind ( item_id ) ) ,
28812887 LifetimeRibKind :: Generics {
28822888 span : generics. span ,
28832889 binder : item_id,
0 commit comments