@@ -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
@@ -870,7 +870,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
870870 ForeignItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
871871 self . with_generic_param_rib (
872872 & generics. params ,
873- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
873+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: ForeignTy ) ,
874874 LifetimeRibKind :: Generics {
875875 binder : foreign_item. id ,
876876 kind : LifetimeBinderKind :: Item ,
@@ -882,7 +882,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
882882 ForeignItemKind :: Fn ( box Fn { ref generics, .. } ) => {
883883 self . with_generic_param_rib (
884884 & generics. params ,
885- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
885+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Fn ) ,
886886 LifetimeRibKind :: Generics {
887887 binder : foreign_item. id ,
888888 kind : LifetimeBinderKind :: Function ,
@@ -891,8 +891,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
891891 |this| visit:: walk_foreign_item ( this, foreign_item) ,
892892 ) ;
893893 }
894- ForeignItemKind :: Static ( .. ) => {
895- self . with_static_rib ( |this| {
894+ ForeignItemKind :: Static ( _ , mutability , _ ) => {
895+ self . with_static_rib ( mutability , |this| {
896896 visit:: walk_foreign_item ( this, foreign_item) ;
897897 } ) ;
898898 }
@@ -2268,10 +2268,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
22682268
22692269 fn resolve_adt ( & mut self , item : & ' ast Item , generics : & ' ast Generics ) {
22702270 debug ! ( "resolve_adt" ) ;
2271+ let kind = match item. kind {
2272+ ItemKind :: Enum ( _, _) => DefKind :: Enum ,
2273+ ItemKind :: Struct ( _, _) => DefKind :: Struct ,
2274+ ItemKind :: Union ( _, _) => DefKind :: Union ,
2275+ // only called if `item` is one of the above
2276+ _ => unreachable ! ( ) ,
2277+ } ;
22712278 self . with_current_self_item ( item, |this| {
22722279 this. with_generic_param_rib (
22732280 & generics. params ,
2274- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2281+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , kind ) ,
22752282 LifetimeRibKind :: Generics {
22762283 binder : item. id ,
22772284 kind : LifetimeBinderKind :: Item ,
@@ -2349,7 +2356,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23492356 ItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
23502357 self . with_generic_param_rib (
23512358 & generics. params ,
2352- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2359+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: TyAlias ) ,
23532360 LifetimeRibKind :: Generics {
23542361 binder : item. id ,
23552362 kind : LifetimeBinderKind :: Item ,
@@ -2362,7 +2369,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23622369 ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
23632370 self . with_generic_param_rib (
23642371 & generics. params ,
2365- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2372+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Fn ) ,
23662373 LifetimeRibKind :: Generics {
23672374 binder : item. id ,
23682375 kind : LifetimeBinderKind :: Function ,
@@ -2401,7 +2408,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24012408 // Create a new rib for the trait-wide type parameters.
24022409 self . with_generic_param_rib (
24032410 & generics. params ,
2404- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2411+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Trait ) ,
24052412 LifetimeRibKind :: Generics {
24062413 binder : item. id ,
24072414 kind : LifetimeBinderKind :: Item ,
@@ -2422,7 +2429,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24222429 // Create a new rib for the trait-wide type parameters.
24232430 self . with_generic_param_rib (
24242431 & generics. params ,
2425- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2432+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: TraitAlias ) ,
24262433 LifetimeRibKind :: Generics {
24272434 binder : item. id ,
24282435 kind : LifetimeBinderKind :: Item ,
@@ -2455,8 +2462,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24552462 } ) ;
24562463 }
24572464
2458- ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2459- self . with_static_rib ( |this| {
2465+ ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, mutability } ) => {
2466+ self . with_static_rib ( mutability , |this| {
24602467 this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
24612468 this. visit_ty ( ty) ;
24622469 } ) ;
@@ -2471,11 +2478,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24712478 ItemKind :: Const ( box ast:: ConstItem { ref generics, ref ty, ref expr, .. } ) => {
24722479 self . with_generic_param_rib (
24732480 & generics. params ,
2474- RibKind :: Item ( if self . r . tcx . features ( ) . generic_const_items {
2475- HasGenericParams :: Yes ( generics. span )
2476- } else {
2477- HasGenericParams :: No
2478- } ) ,
2481+ RibKind :: Item (
2482+ if self . r . tcx . features ( ) . generic_const_items {
2483+ HasGenericParams :: Yes ( generics. span )
2484+ } else {
2485+ HasGenericParams :: No
2486+ } ,
2487+ DefKind :: Const ,
2488+ ) ,
24792489 LifetimeRibKind :: Generics {
24802490 binder : item. id ,
24812491 kind : LifetimeBinderKind :: ConstItem ,
@@ -2560,7 +2570,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
25602570 let mut add_bindings_for_ns = |ns| {
25612571 let parent_rib = self . ribs [ ns]
25622572 . iter ( )
2563- . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( _ ) ) )
2573+ . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( .. ) ) )
25642574 . expect ( "associated item outside of an item" ) ;
25652575 seen_bindings. extend ( parent_rib. bindings . keys ( ) . map ( |ident| ( * ident, ident. span ) ) ) ;
25662576 } ;
@@ -2695,8 +2705,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26952705 self . label_ribs . pop ( ) ;
26962706 }
26972707
2698- fn with_static_rib ( & mut self , f : impl FnOnce ( & mut Self ) ) {
2699- let kind = RibKind :: Item ( HasGenericParams :: No ) ;
2708+ fn with_static_rib ( & mut self , mutability : Mutability , f : impl FnOnce ( & mut Self ) ) {
2709+ let kind = RibKind :: Item ( HasGenericParams :: No , DefKind :: Static ( mutability ) ) ;
27002710 self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
27012711 }
27022712
@@ -2877,7 +2887,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28772887 // If applicable, create a rib for the type parameters.
28782888 self . with_generic_param_rib (
28792889 & generics. params ,
2880- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2890+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Impl { of_trait : opt_trait_reference . is_some ( ) } ) ,
28812891 LifetimeRibKind :: Generics {
28822892 span : generics. span ,
28832893 binder : item_id,
0 commit comments