@@ -181,7 +181,7 @@ pub(crate) enum RibKind<'a> {
181
181
FnOrCoroutine ,
182
182
183
183
/// We passed through an item scope. Disallow upvars.
184
- Item ( HasGenericParams ) ,
184
+ Item ( HasGenericParams , DefKind ) ,
185
185
186
186
/// We're in a constant item. Can't refer to dynamic stuff.
187
187
///
@@ -221,7 +221,7 @@ impl RibKind<'_> {
221
221
| RibKind :: MacroDefinition ( _)
222
222
| RibKind :: ConstParamTy
223
223
| RibKind :: InlineAsmSym => false ,
224
- RibKind :: AssocItem | RibKind :: Item ( _ ) | RibKind :: ForwardGenericParamBan => true ,
224
+ RibKind :: AssocItem | RibKind :: Item ( .. ) | RibKind :: ForwardGenericParamBan => true ,
225
225
}
226
226
}
227
227
@@ -866,11 +866,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
866
866
}
867
867
fn visit_foreign_item ( & mut self , foreign_item : & ' ast ForeignItem ) {
868
868
self . resolve_doc_links ( & foreign_item. attrs , MaybeExported :: Ok ( foreign_item. id ) ) ;
869
+ let def_kind = self . r . local_def_kind ( foreign_item. id ) ;
869
870
match foreign_item. kind {
870
871
ForeignItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
871
872
self . with_generic_param_rib (
872
873
& generics. params ,
873
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
874
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
874
875
LifetimeRibKind :: Generics {
875
876
binder : foreign_item. id ,
876
877
kind : LifetimeBinderKind :: Item ,
@@ -882,7 +883,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
882
883
ForeignItemKind :: Fn ( box Fn { ref generics, .. } ) => {
883
884
self . with_generic_param_rib (
884
885
& generics. params ,
885
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
886
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
886
887
LifetimeRibKind :: Generics {
887
888
binder : foreign_item. id ,
888
889
kind : LifetimeBinderKind :: Function ,
@@ -892,7 +893,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
892
893
) ;
893
894
}
894
895
ForeignItemKind :: Static ( ..) => {
895
- self . with_static_rib ( |this| {
896
+ self . with_static_rib ( def_kind , |this| {
896
897
visit:: walk_foreign_item ( this, foreign_item) ;
897
898
} ) ;
898
899
}
@@ -2268,10 +2269,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2268
2269
2269
2270
fn resolve_adt ( & mut self , item : & ' ast Item , generics : & ' ast Generics ) {
2270
2271
debug ! ( "resolve_adt" ) ;
2272
+ let kind = self . r . local_def_kind ( item. id ) ;
2271
2273
self . with_current_self_item ( item, |this| {
2272
2274
this. with_generic_param_rib (
2273
2275
& generics. params ,
2274
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2276
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , kind ) ,
2275
2277
LifetimeRibKind :: Generics {
2276
2278
binder : item. id ,
2277
2279
kind : LifetimeBinderKind :: Item ,
@@ -2345,11 +2347,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2345
2347
let name = item. ident . name ;
2346
2348
debug ! ( "(resolving item) resolving {} ({:?})" , name, item. kind) ;
2347
2349
2350
+ let def_kind = self . r . local_def_kind ( item. id ) ;
2348
2351
match item. kind {
2349
2352
ItemKind :: TyAlias ( box TyAlias { ref generics, .. } ) => {
2350
2353
self . with_generic_param_rib (
2351
2354
& generics. params ,
2352
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2355
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2353
2356
LifetimeRibKind :: Generics {
2354
2357
binder : item. id ,
2355
2358
kind : LifetimeBinderKind :: Item ,
@@ -2362,7 +2365,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2362
2365
ItemKind :: Fn ( box Fn { ref generics, .. } ) => {
2363
2366
self . with_generic_param_rib (
2364
2367
& generics. params ,
2365
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2368
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2366
2369
LifetimeRibKind :: Generics {
2367
2370
binder : item. id ,
2368
2371
kind : LifetimeBinderKind :: Function ,
@@ -2401,7 +2404,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2401
2404
// Create a new rib for the trait-wide type parameters.
2402
2405
self . with_generic_param_rib (
2403
2406
& generics. params ,
2404
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2407
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2405
2408
LifetimeRibKind :: Generics {
2406
2409
binder : item. id ,
2407
2410
kind : LifetimeBinderKind :: Item ,
@@ -2422,7 +2425,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2422
2425
// Create a new rib for the trait-wide type parameters.
2423
2426
self . with_generic_param_rib (
2424
2427
& generics. params ,
2425
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2428
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , def_kind ) ,
2426
2429
LifetimeRibKind :: Generics {
2427
2430
binder : item. id ,
2428
2431
kind : LifetimeBinderKind :: Item ,
@@ -2456,7 +2459,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2456
2459
}
2457
2460
2458
2461
ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2459
- self . with_static_rib ( |this| {
2462
+ self . with_static_rib ( def_kind , |this| {
2460
2463
this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
2461
2464
this. visit_ty ( ty) ;
2462
2465
} ) ;
@@ -2471,11 +2474,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2471
2474
ItemKind :: Const ( box ast:: ConstItem { ref generics, ref ty, ref expr, .. } ) => {
2472
2475
self . with_generic_param_rib (
2473
2476
& 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
+ ) ,
2479
2485
LifetimeRibKind :: Generics {
2480
2486
binder : item. id ,
2481
2487
kind : LifetimeBinderKind :: ConstItem ,
@@ -2560,7 +2566,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2560
2566
let mut add_bindings_for_ns = |ns| {
2561
2567
let parent_rib = self . ribs [ ns]
2562
2568
. iter ( )
2563
- . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( _ ) ) )
2569
+ . rfind ( |r| matches ! ( r. kind, RibKind :: Item ( .. ) ) )
2564
2570
. expect ( "associated item outside of an item" ) ;
2565
2571
seen_bindings. extend ( parent_rib. bindings . keys ( ) . map ( |ident| ( * ident, ident. span ) ) ) ;
2566
2572
} ;
@@ -2695,8 +2701,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2695
2701
self . label_ribs . pop ( ) ;
2696
2702
}
2697
2703
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 ) ;
2700
2706
self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
2701
2707
}
2702
2708
@@ -2877,7 +2883,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2877
2883
// If applicable, create a rib for the type parameters.
2878
2884
self . with_generic_param_rib (
2879
2885
& generics. params ,
2880
- RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) ) ,
2886
+ RibKind :: Item ( HasGenericParams :: Yes ( generics. span ) , self . r . local_def_kind ( item_id ) ) ,
2881
2887
LifetimeRibKind :: Generics {
2882
2888
span : generics. span ,
2883
2889
binder : item_id,
0 commit comments