@@ -185,7 +185,7 @@ pub(crate) enum RibKind<'a> {
185
185
FnOrCoroutine ,
186
186
187
187
/// We passed through an item scope. Disallow upvars.
188
- Item ( HasGenericParams ) ,
188
+ Item ( HasGenericParams , DefKind ) ,
189
189
190
190
/// We're in a constant item. Can't refer to dynamic stuff.
191
191
///
@@ -225,7 +225,7 @@ impl RibKind<'_> {
225
225
| RibKind :: MacroDefinition ( _)
226
226
| RibKind :: ConstParamTy
227
227
| RibKind :: InlineAsmSym => false ,
228
- RibKind :: AssocItem | RibKind :: Item ( _ ) | RibKind :: ForwardGenericParamBan => true ,
228
+ RibKind :: AssocItem | RibKind :: Item ( .. ) | RibKind :: ForwardGenericParamBan => true ,
229
229
}
230
230
}
231
231
@@ -869,11 +869,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
869
869
}
870
870
fn visit_foreign_item ( & mut self , foreign_item : & ' ast ForeignItem ) {
871
871
self . resolve_doc_links ( & foreign_item. attrs , MaybeExported :: Ok ( foreign_item. id ) ) ;
872
+ let def_kind = self . r . local_def_kind ( foreign_item. id ) ;
872
873
match foreign_item. kind {
873
874
ForeignItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
874
875
self . with_generic_param_rib (
875
876
& generics. params ,
876
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
877
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
877
878
LifetimeRibKind :: Generics {
878
879
binder : foreign_item. id ,
879
880
kind : LifetimeBinderKind :: Item ,
@@ -885,7 +886,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
885
886
ForeignItemKind :: Fn ( box Fn { ref generics, .. } ) => {
886
887
self . with_generic_param_rib (
887
888
& generics. params ,
888
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
889
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
889
890
LifetimeRibKind :: Generics {
890
891
binder : foreign_item. id ,
891
892
kind : LifetimeBinderKind :: Function ,
@@ -895,7 +896,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
895
896
) ;
896
897
}
897
898
ForeignItemKind :: Static ( ..) => {
898
- self . with_static_rib ( |this| {
899
+ self . with_static_rib ( def_kind , |this| {
899
900
visit:: walk_foreign_item ( this, foreign_item) ;
900
901
} ) ;
901
902
}
@@ -2266,10 +2267,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2266
2267
2267
2268
fn resolve_adt ( & mut self , item : & ' ast Item , generics : & ' ast Generics ) {
2268
2269
debug ! ( "resolve_adt" ) ;
2270
+ let kind = self . r . local_def_kind ( item. id ) ;
2269
2271
self . with_current_self_item ( item, |this| {
2270
2272
this. with_generic_param_rib (
2271
2273
& generics. params ,
2272
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2274
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , kind ) ,
2273
2275
LifetimeRibKind :: Generics {
2274
2276
binder : item. id ,
2275
2277
kind : LifetimeBinderKind :: Item ,
@@ -2343,11 +2345,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2343
2345
let name = item. ident . name ;
2344
2346
debug ! ( "(resolving item) resolving {} ({:?})" , name, item. kind) ;
2345
2347
2348
+ let def_kind = self . r . local_def_kind ( item. id ) ;
2346
2349
match item. kind {
2347
2350
ItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
2348
2351
self . with_generic_param_rib (
2349
2352
& generics. params ,
2350
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2353
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2351
2354
LifetimeRibKind :: Generics {
2352
2355
binder : item. id ,
2353
2356
kind : LifetimeBinderKind :: Item ,
@@ -2360,7 +2363,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2360
2363
ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
2361
2364
self . with_generic_param_rib (
2362
2365
& generics. params ,
2363
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2366
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2364
2367
LifetimeRibKind :: Generics {
2365
2368
binder : item. id ,
2366
2369
kind : LifetimeBinderKind :: Function ,
@@ -2399,7 +2402,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2399
2402
// Create a new rib for the trait-wide type parameters.
2400
2403
self . with_generic_param_rib (
2401
2404
& generics. params ,
2402
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2405
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2403
2406
LifetimeRibKind :: Generics {
2404
2407
binder : item. id ,
2405
2408
kind : LifetimeBinderKind :: Item ,
@@ -2420,7 +2423,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2420
2423
// Create a new rib for the trait-wide type parameters.
2421
2424
self . with_generic_param_rib (
2422
2425
& generics. params ,
2423
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2426
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2424
2427
LifetimeRibKind :: Generics {
2425
2428
binder : item. id ,
2426
2429
kind : LifetimeBinderKind :: Item ,
@@ -2454,7 +2457,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2454
2457
}
2455
2458
2456
2459
ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2457
- self . with_static_rib ( |this| {
2460
+ self . with_static_rib ( def_kind , |this| {
2458
2461
this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
2459
2462
this. visit_ty ( ty) ;
2460
2463
} ) ;
@@ -2469,11 +2472,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2469
2472
ItemKind :: Const ( box ast:: ConstItem { ref generics, ref ty, ref expr, .. } ) => {
2470
2473
self . with_generic_param_rib (
2471
2474
& generics. params ,
2472
- RibKind :: Item ( if self . r . tcx . features ( ) . generic_const_items {
2473
- HasGenericParams :: Yes ( generics. span )
2474
- } else {
2475
- HasGenericParams :: No
2476
- } ) ,
2475
+ RibKind :: Item (
2476
+ if self . r . tcx . features ( ) . generic_const_items {
2477
+ HasGenericParams :: Yes ( generics. span )
2478
+ } else {
2479
+ HasGenericParams :: No
2480
+ } ,
2481
+ def_kind,
2482
+ ) ,
2477
2483
LifetimeRibKind :: Generics {
2478
2484
binder : item. id ,
2479
2485
kind : LifetimeBinderKind :: ConstItem ,
@@ -2558,7 +2564,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2558
2564
let mut add_bindings_for_ns = |ns| {
2559
2565
let parent_rib = self . ribs [ ns]
2560
2566
. iter ( )
2561
- . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( _ ) ) )
2567
+ . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( .. ) ) )
2562
2568
. expect ( "associated item outside of an item" ) ;
2563
2569
seen_bindings. extend ( parent_rib. bindings . keys ( ) . map ( |ident| ( * ident, ident. span ) ) ) ;
2564
2570
} ;
@@ -2693,8 +2699,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2693
2699
self . label_ribs . pop ( ) ;
2694
2700
}
2695
2701
2696
- fn with_static_rib ( & mut self , f : impl FnOnce ( & mut Self ) ) {
2697
- let kind = RibKind :: Item ( HasGenericParams :: No ) ;
2702
+ fn with_static_rib ( & mut self , def_kind : DefKind , f : impl FnOnce ( & mut Self ) ) {
2703
+ let kind = RibKind :: Item ( HasGenericParams :: No , def_kind ) ;
2698
2704
self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
2699
2705
}
2700
2706
@@ -2875,7 +2881,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2875
2881
// If applicable, create a rib for the type parameters.
2876
2882
self . with_generic_param_rib (
2877
2883
& generics. params ,
2878
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2884
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , self . r . local_def_kind ( item_id ) ) ,
2879
2885
LifetimeRibKind :: Generics {
2880
2886
span : generics. span ,
2881
2887
binder : item_id,
0 commit comments