@@ -53,7 +53,7 @@ use rustc_middle::middle::privacy::EffectiveVisibilities;
53
53
use rustc_middle:: query:: Providers ;
54
54
use rustc_middle:: span_bug;
55
55
use rustc_middle:: ty:: { self , MainDefinition , RegisteredTools , TyCtxt , TyCtxtFeed } ;
56
- use rustc_middle:: ty:: { ResolverGlobalCtxt , ResolverOutputs } ;
56
+ use rustc_middle:: ty:: { ResolverGlobalCtxt , ResolverOutputs , Feed } ;
57
57
use rustc_query_system:: ich:: StableHashingContext ;
58
58
use rustc_session:: lint:: builtin:: PRIVATE_MACRO_USE ;
59
59
use rustc_session:: lint:: LintBuffer ;
@@ -1115,7 +1115,7 @@ pub struct Resolver<'a, 'tcx> {
1115
1115
1116
1116
next_node_id : NodeId ,
1117
1117
1118
- node_id_to_def_id : NodeMap < LocalDefId > ,
1118
+ node_id_to_def_id : NodeMap < Feed < ' tcx , LocalDefId > > ,
1119
1119
def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
1120
1120
1121
1121
/// Indices of unnamed struct or variant fields with unresolved attributes.
@@ -1231,11 +1231,19 @@ impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> {
1231
1231
1232
1232
impl < ' tcx > Resolver < ' _ , ' tcx > {
1233
1233
fn opt_local_def_id ( & self , node : NodeId ) -> Option < LocalDefId > {
1234
- self . node_id_to_def_id . get ( & node) . copied ( )
1234
+ self . opt_feed ( node) . map ( |f| f . key ( ) )
1235
1235
}
1236
1236
1237
1237
fn local_def_id ( & self , node : NodeId ) -> LocalDefId {
1238
- self . opt_local_def_id ( node) . unwrap_or_else ( || panic ! ( "no entry for node id: `{node:?}`" ) )
1238
+ self . feed ( node) . key ( )
1239
+ }
1240
+
1241
+ fn opt_feed ( & self , node : NodeId ) -> Option < Feed < ' tcx , LocalDefId > > {
1242
+ self . node_id_to_def_id . get ( & node) . copied ( )
1243
+ }
1244
+
1245
+ fn feed ( & self , node : NodeId ) -> Feed < ' tcx , LocalDefId > {
1246
+ self . opt_feed ( node) . unwrap_or_else ( || panic ! ( "no entry for node id: `{node:?}`" ) )
1239
1247
}
1240
1248
1241
1249
fn local_def_kind ( & self , node : NodeId ) -> DefKind {
@@ -1258,7 +1266,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
1258
1266
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}" ,
1259
1267
node_id,
1260
1268
data,
1261
- self . tcx. definitions_untracked( ) . def_key( self . node_id_to_def_id[ & node_id] ) ,
1269
+ self . tcx. definitions_untracked( ) . def_key( self . node_id_to_def_id[ & node_id] . key ( ) ) ,
1262
1270
) ;
1263
1271
1264
1272
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
@@ -1280,7 +1288,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
1280
1288
// we don't need a mapping from `NodeId` to `LocalDefId`.
1281
1289
if node_id != ast:: DUMMY_NODE_ID {
1282
1290
debug ! ( "create_def: def_id_to_node_id[{:?}] <-> {:?}" , def_id, node_id) ;
1283
- self . node_id_to_def_id . insert ( node_id, def_id ) ;
1291
+ self . node_id_to_def_id . insert ( node_id, feed . downgrade ( ) ) ;
1284
1292
}
1285
1293
assert_eq ! ( self . def_id_to_node_id. push( node_id) , def_id) ;
1286
1294
@@ -1332,7 +1340,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1332
1340
let mut def_id_to_node_id = IndexVec :: default ( ) ;
1333
1341
assert_eq ! ( def_id_to_node_id. push( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
1334
1342
let mut node_id_to_def_id = NodeMap :: default ( ) ;
1335
- node_id_to_def_id. insert ( CRATE_NODE_ID , CRATE_DEF_ID ) ;
1343
+ let crate_feed = tcx. feed_local_def_id ( CRATE_DEF_ID ) . downgrade ( ) ;
1344
+ node_id_to_def_id. insert ( CRATE_NODE_ID , crate_feed) ;
1336
1345
1337
1346
let mut invocation_parents = FxHashMap :: default ( ) ;
1338
1347
invocation_parents. insert ( LocalExpnId :: ROOT , ( CRATE_DEF_ID , ImplTraitContext :: Existential ) ) ;
@@ -1548,7 +1557,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1548
1557
1549
1558
self . tcx . feed_local_crate ( ) . stripped_cfg_items ( self . tcx . arena . alloc_from_iter (
1550
1559
self . stripped_cfg_items . into_iter ( ) . filter_map ( |item| {
1551
- let parent_module = self . node_id_to_def_id . get ( & item. parent_module ) ?. to_def_id ( ) ;
1560
+ let parent_module =
1561
+ self . node_id_to_def_id . get ( & item. parent_module ) ?. key ( ) . to_def_id ( ) ;
1552
1562
Some ( StrippedCfgItem { parent_module, name : item. name , cfg : item. cfg } )
1553
1563
} ) ,
1554
1564
) ) ;
@@ -1577,7 +1587,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1577
1587
lifetimes_res_map : self . lifetimes_res_map ,
1578
1588
extra_lifetime_params_map : self . extra_lifetime_params_map ,
1579
1589
next_node_id : self . next_node_id ,
1580
- node_id_to_def_id : self . node_id_to_def_id ,
1590
+ node_id_to_def_id : self
1591
+ . node_id_to_def_id
1592
+ . into_items ( )
1593
+ . map ( |( k, f) | ( k, f. key ( ) ) )
1594
+ . collect ( ) ,
1581
1595
def_id_to_node_id : self . def_id_to_node_id ,
1582
1596
trait_map : self . trait_map ,
1583
1597
lifetime_elision_allowed : self . lifetime_elision_allowed ,
0 commit comments