@@ -181,7 +181,8 @@ pub(crate) enum RibKind<'a> {
181181 FnOrCoroutine ,
182182
183183 /// We passed through an item scope. Disallow upvars.
184- Item ( HasGenericParams ) ,
184+ /// Note if this is a static/const to help with some confusing diagnostics
185+ Item ( HasGenericParams , DefKind ) ,
185186
186187 /// We're in a constant item. Can't refer to dynamic stuff.
187188 ///
@@ -221,7 +222,7 @@ impl RibKind<'_> {
221222 | RibKind :: MacroDefinition ( _)
222223 | RibKind :: ConstParamTy
223224 | RibKind :: InlineAsmSym => false ,
224- RibKind :: AssocItem | RibKind :: Item ( _ ) | RibKind :: ForwardGenericParamBan => true ,
225+ RibKind :: AssocItem | RibKind :: Item ( .. ) | RibKind :: ForwardGenericParamBan => true ,
225226 }
226227 }
227228
@@ -870,7 +871,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
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 ) , DefKind :: ForeignTy ) ,
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 ) , DefKind :: Fn ) ,
886887 LifetimeRibKind :: Generics {
887888 binder : foreign_item. id ,
888889 kind : LifetimeBinderKind :: Function ,
@@ -891,8 +892,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
891892 |this| visit:: walk_foreign_item ( this, foreign_item) ,
892893 ) ;
893894 }
894- ForeignItemKind :: Static ( .. ) => {
895- self . with_static_rib ( |this| {
895+ ForeignItemKind :: Static ( _ , mutability , _ ) => {
896+ self . with_static_rib ( mutability , |this| {
896897 visit:: walk_foreign_item ( this, foreign_item) ;
897898 } ) ;
898899 }
@@ -2268,10 +2269,17 @@ 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 = match item. kind {
2273+ ItemKind :: Enum ( _, _) => DefKind :: Enum ,
2274+ ItemKind :: Struct ( _, _) => DefKind :: Struct ,
2275+ ItemKind :: Union ( _, _) => DefKind :: Union ,
2276+ // only called if `item` is one of the above
2277+ _ => unreachable ! ( ) ,
2278+ } ;
22712279 self . with_current_self_item ( item, |this| {
22722280 this. with_generic_param_rib (
22732281 & generics. params ,
2274- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2282+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , kind ) ,
22752283 LifetimeRibKind :: Generics {
22762284 binder : item. id ,
22772285 kind : LifetimeBinderKind :: Item ,
@@ -2349,7 +2357,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23492357 ItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
23502358 self . with_generic_param_rib (
23512359 & generics. params ,
2352- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2360+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: TyAlias ) ,
23532361 LifetimeRibKind :: Generics {
23542362 binder : item. id ,
23552363 kind : LifetimeBinderKind :: Item ,
@@ -2362,7 +2370,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23622370 ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
23632371 self . with_generic_param_rib (
23642372 & generics. params ,
2365- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2373+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Fn ) ,
23662374 LifetimeRibKind :: Generics {
23672375 binder : item. id ,
23682376 kind : LifetimeBinderKind :: Function ,
@@ -2401,7 +2409,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24012409 // Create a new rib for the trait-wide type parameters.
24022410 self . with_generic_param_rib (
24032411 & generics. params ,
2404- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2412+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Trait ) ,
24052413 LifetimeRibKind :: Generics {
24062414 binder : item. id ,
24072415 kind : LifetimeBinderKind :: Item ,
@@ -2422,7 +2430,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24222430 // Create a new rib for the trait-wide type parameters.
24232431 self . with_generic_param_rib (
24242432 & generics. params ,
2425- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2433+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: TraitAlias ) ,
24262434 LifetimeRibKind :: Generics {
24272435 binder : item. id ,
24282436 kind : LifetimeBinderKind :: Item ,
@@ -2455,8 +2463,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24552463 } ) ;
24562464 }
24572465
2458- ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2459- self . with_static_rib ( |this| {
2466+ ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, mutability } ) => {
2467+ self . with_static_rib ( mutability , |this| {
24602468 this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
24612469 this. visit_ty ( ty) ;
24622470 } ) ;
@@ -2471,11 +2479,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24712479 ItemKind :: Const ( box ast:: ConstItem { ref generics, ref ty, ref expr, .. } ) => {
24722480 self . with_generic_param_rib (
24732481 & generics. params ,
2474- RibKind :: Item ( if self . r . tcx . features ( ) . generic_const_items {
2475- HasGenericParams :: Yes ( generics. span )
2476- } else {
2477- HasGenericParams :: No
2478- } ) ,
2482+ RibKind :: Item (
2483+ if self . r . tcx . features ( ) . generic_const_items {
2484+ HasGenericParams :: Yes ( generics. span )
2485+ } else {
2486+ HasGenericParams :: No
2487+ } ,
2488+ DefKind :: Const ,
2489+ ) ,
24792490 LifetimeRibKind :: Generics {
24802491 binder : item. id ,
24812492 kind : LifetimeBinderKind :: ConstItem ,
@@ -2560,7 +2571,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
25602571 let mut add_bindings_for_ns = |ns| {
25612572 let parent_rib = self . ribs [ ns]
25622573 . iter ( )
2563- . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( _ ) ) )
2574+ . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( .. ) ) )
25642575 . expect ( "associated item outside of an item" ) ;
25652576 seen_bindings. extend ( parent_rib. bindings . keys ( ) . map ( |ident| ( * ident, ident. span ) ) ) ;
25662577 } ;
@@ -2695,8 +2706,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26952706 self . label_ribs . pop ( ) ;
26962707 }
26972708
2698- fn with_static_rib ( & mut self , f : impl FnOnce ( & mut Self ) ) {
2699- let kind = RibKind :: Item ( HasGenericParams :: No ) ;
2709+ fn with_static_rib ( & mut self , mutability : Mutability , f : impl FnOnce ( & mut Self ) ) {
2710+ let kind = RibKind :: Item ( HasGenericParams :: No , DefKind :: Static ( mutability ) ) ;
27002711 self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
27012712 }
27022713
@@ -2877,7 +2888,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
28772888 // If applicable, create a rib for the type parameters.
28782889 self . with_generic_param_rib (
28792890 & generics. params ,
2880- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2891+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , DefKind :: Impl { of_trait : opt_trait_reference . is_some ( ) } ) ,
28812892 LifetimeRibKind :: Generics {
28822893 span : generics. span ,
28832894 binder : item_id,
0 commit comments