@@ -62,6 +62,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6262 owner : NodeId ,
6363 f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
6464 ) {
65+ let next_node_id = self . resolver . next_node_id ;
6566 let mut lctx = LoweringContext {
6667 // Pseudo-globals.
6768 sess : & self . sess ,
@@ -79,6 +80,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
7980 node_id_to_local_id : Default :: default ( ) ,
8081 local_id_to_def_id : SortedMap :: new ( ) ,
8182 trait_map : Default :: default ( ) ,
83+ local_node_id_to_def_id : FxHashMap :: default ( ) ,
84+ next_node_id,
8285
8386 // Lowering state.
8487 catch_scope : None ,
@@ -126,8 +129,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
126129
127130 #[ instrument( level = "debug" , skip( self , c) ) ]
128131 fn lower_crate ( & mut self , c : & Crate ) {
129- debug_assert_eq ! ( self . resolver. local_def_id( CRATE_NODE_ID ) , CRATE_DEF_ID ) ;
130-
132+ debug_assert_eq ! ( self . resolver. node_id_to_def_id[ & CRATE_NODE_ID ] , CRATE_DEF_ID ) ;
131133 self . with_lctx ( CRATE_NODE_ID , |lctx| {
132134 let module = lctx. lower_mod ( & c. items , & c. spans ) ;
133135 lctx. lower_attrs ( hir:: CRATE_HIR_ID , & c. attrs ) ;
@@ -141,7 +143,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
141143 }
142144
143145 fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) {
144- let def_id = self . resolver . local_def_id ( item. id ) ;
146+ let def_id = self . resolver . node_id_to_def_id [ & item. id ] ;
145147
146148 let parent_id = {
147149 let parent = self . definitions . def_key ( def_id) . parent ;
@@ -185,7 +187,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
185187 }
186188
187189 pub ( super ) fn lower_item_ref ( & mut self , i : & Item ) -> SmallVec < [ hir:: ItemId ; 1 ] > {
188- let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . resolver . local_def_id( i. id) } ] ;
190+ let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . local_def_id( i. id) } ] ;
189191 if let ItemKind :: Use ( ref use_tree) = & i. kind {
190192 self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
191193 }
@@ -201,7 +203,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
201203 match tree. kind {
202204 UseTreeKind :: Nested ( ref nested_vec) => {
203205 for & ( ref nested, id) in nested_vec {
204- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
206+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
205207 self . lower_item_id_use_tree ( nested, id, vec) ;
206208 }
207209 }
@@ -210,7 +212,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
210212 for ( _, & id) in
211213 iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
212214 {
213- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
215+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
214216 }
215217 }
216218 }
@@ -475,7 +477,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
475477 }
476478 ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
477479 let body = P ( self . lower_mac_args ( body) ) ;
478- let macro_kind = self . resolver . decl_macro_kind ( self . resolver . local_def_id ( id) ) ;
480+ let macro_kind = self . resolver . decl_macro_kind ( self . local_def_id ( id) ) ;
479481 hir:: ItemKind :: Macro ( ast:: MacroDef { body, macro_rules } , macro_kind)
480482 }
481483 ItemKind :: MacCall ( ..) => {
@@ -535,7 +537,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
535537 // Essentially a single `use` which imports two names is desugared into
536538 // two imports.
537539 for new_node_id in [ id1, id2] {
538- let new_id = self . resolver . local_def_id ( new_node_id) ;
540+ let new_id = self . local_def_id ( new_node_id) ;
539541 let Some ( res) = resolutions. next ( ) else {
540542 // Associate an HirId to both ids even if there is no resolution.
541543 let _old = self . children . insert (
@@ -548,7 +550,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
548550 let ident = * ident;
549551 let mut path = path. clone ( ) ;
550552 for seg in & mut path. segments {
551- seg. id = self . resolver . next_node_id ( ) ;
553+ seg. id = self . next_node_id ( ) ;
552554 }
553555 let span = path. span ;
554556
@@ -611,13 +613,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
611613
612614 // Add all the nested `PathListItem`s to the HIR.
613615 for & ( ref use_tree, id) in trees {
614- let new_hir_id = self . resolver . local_def_id ( id) ;
616+ let new_hir_id = self . local_def_id ( id) ;
615617
616618 let mut prefix = prefix. clone ( ) ;
617619
618620 // Give the segments new node-ids since they are being cloned.
619621 for seg in & mut prefix. segments {
620- seg. id = self . resolver . next_node_id ( ) ;
622+ seg. id = self . next_node_id ( ) ;
621623 }
622624
623625 // Each `use` import is an item and thus are owners of the
@@ -691,7 +693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
691693
692694 fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef {
693695 hir:: ForeignItemRef {
694- id : hir:: ForeignItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
696+ id : hir:: ForeignItemId { def_id : self . local_def_id ( i. id ) } ,
695697 ident : self . lower_ident ( i. ident ) ,
696698 span : self . lower_span ( i. span ) ,
697699 }
@@ -847,7 +849,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
847849 }
848850 AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
849851 } ;
850- let id = hir:: TraitItemId { def_id : self . resolver . local_def_id ( i. id ) } ;
852+ let id = hir:: TraitItemId { def_id : self . local_def_id ( i. id ) } ;
851853 let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
852854 hir:: TraitItemRef {
853855 id,
@@ -927,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
927929 let has_value = true ;
928930 let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
929931 hir:: ImplItemRef {
930- id : hir:: ImplItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
932+ id : hir:: ImplItemId { def_id : self . local_def_id ( i. id ) } ,
931933 ident : self . lower_ident ( i. ident ) ,
932934 span : self . lower_span ( i. span ) ,
933935 defaultness,
@@ -1339,7 +1341,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13391341 generics
13401342 . params
13411343 . iter ( )
1342- . any ( |p| def_id == self . resolver . local_def_id ( p. id ) . to_def_id ( ) )
1344+ . any ( |p| def_id == self . local_def_id ( p. id ) . to_def_id ( ) )
13431345 }
13441346 // Either the `bounded_ty` is not a plain type parameter, or
13451347 // it's not found in the generic type parameters list.
@@ -1443,7 +1445,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14431445 match kind {
14441446 GenericParamKind :: Const { .. } => None ,
14451447 GenericParamKind :: Type { .. } => {
1446- let def_id = self . resolver . local_def_id ( id) . to_def_id ( ) ;
1448+ let def_id = self . local_def_id ( id) . to_def_id ( ) ;
14471449 let ty_path = self . arena . alloc ( hir:: Path {
14481450 span : param_span,
14491451 res : Res :: Def ( DefKind :: TyParam , def_id) ,
@@ -1466,7 +1468,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14661468 let res = self . resolver . get_lifetime_res ( id) . unwrap_or_else ( || {
14671469 panic ! ( "Missing resolution for lifetime {:?} at {:?}" , id, ident. span)
14681470 } ) ;
1469- let lt_id = self . resolver . next_node_id ( ) ;
1471+ let lt_id = self . next_node_id ( ) ;
14701472 let lifetime = self . new_named_lifetime_with_res ( lt_id, ident_span, ident, res) ;
14711473 Some ( hir:: WherePredicate :: RegionPredicate ( hir:: WhereRegionPredicate {
14721474 lifetime,
0 commit comments