@@ -53,7 +53,7 @@ use rustc_middle::middle::privacy::EffectiveVisibilities;
5353use rustc_middle:: query:: Providers ;
5454use rustc_middle:: span_bug;
5555use rustc_middle:: ty:: { self , MainDefinition , RegisteredTools , TyCtxt , TyCtxtFeed } ;
56- use rustc_middle:: ty:: { ResolverGlobalCtxt , ResolverOutputs } ;
56+ use rustc_middle:: ty:: { ResolverGlobalCtxt , ResolverOutputs , Feed } ;
5757use rustc_query_system:: ich:: StableHashingContext ;
5858use rustc_session:: lint:: builtin:: PRIVATE_MACRO_USE ;
5959use rustc_session:: lint:: LintBuffer ;
@@ -1115,7 +1115,7 @@ pub struct Resolver<'a, 'tcx> {
11151115
11161116 next_node_id : NodeId ,
11171117
1118- node_id_to_def_id : NodeMap < LocalDefId > ,
1118+ node_id_to_def_id : NodeMap < Feed < ' tcx , LocalDefId > > ,
11191119 def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
11201120
11211121 /// 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> {
12311231
12321232impl < ' tcx > Resolver < ' _ , ' tcx > {
12331233 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 ( ) )
12351235 }
12361236
12371237 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:?}`" ) )
12391247 }
12401248
12411249 fn local_def_kind ( & self , node : NodeId ) -> DefKind {
@@ -1258,7 +1266,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
12581266 "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}" ,
12591267 node_id,
12601268 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 ( ) ) ,
12621270 ) ;
12631271
12641272 // 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> {
12801288 // we don't need a mapping from `NodeId` to `LocalDefId`.
12811289 if node_id != ast:: DUMMY_NODE_ID {
12821290 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 ( ) ) ;
12841292 }
12851293 assert_eq ! ( self . def_id_to_node_id. push( node_id) , def_id) ;
12861294
@@ -1332,7 +1340,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13321340 let mut def_id_to_node_id = IndexVec :: default ( ) ;
13331341 assert_eq ! ( def_id_to_node_id. push( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
13341342 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) ;
13361345
13371346 let mut invocation_parents = FxHashMap :: default ( ) ;
13381347 invocation_parents. insert ( LocalExpnId :: ROOT , ( CRATE_DEF_ID , ImplTraitContext :: Existential ) ) ;
@@ -1548,7 +1557,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15481557
15491558 self . tcx . feed_local_crate ( ) . stripped_cfg_items ( self . tcx . arena . alloc_from_iter (
15501559 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 ( ) ;
15521562 Some ( StrippedCfgItem { parent_module, name : item. name , cfg : item. cfg } )
15531563 } ) ,
15541564 ) ) ;
@@ -1577,7 +1587,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15771587 lifetimes_res_map : self . lifetimes_res_map ,
15781588 extra_lifetime_params_map : self . extra_lifetime_params_map ,
15791589 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 ( ) ,
15811595 def_id_to_node_id : self . def_id_to_node_id ,
15821596 trait_map : self . trait_map ,
15831597 lifetime_elision_allowed : self . lifetime_elision_allowed ,
0 commit comments