@@ -64,6 +64,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6464 owner : NodeId ,
6565 f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
6666 ) {
67+ let next_node_id = self . resolver . next_node_id ;
6768 let mut lctx = LoweringContext {
6869 // Pseudo-globals.
6970 sess : & self . sess ,
@@ -82,6 +83,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
8283 node_id_to_local_id : Default :: default ( ) ,
8384 local_id_to_def_id : SortedMap :: new ( ) ,
8485 trait_map : Default :: default ( ) ,
86+ local_node_id_to_def_id : FxHashMap :: default ( ) ,
87+ next_node_id,
8588
8689 // Lowering state.
8790 catch_scope : None ,
@@ -126,8 +129,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
126129 }
127130
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 ) ;
@@ -140,7 +142,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
140142 }
141143
142144 fn lower_assoc_item ( & mut self , item : & AssocItem , ctxt : AssocCtxt ) {
143- let def_id = self . resolver . local_def_id ( item. id ) ;
145+ let def_id = self . resolver . node_id_to_def_id [ & item. id ] ;
144146
145147 let parent_id = {
146148 let parent = self . definitions . def_key ( def_id) . parent ;
@@ -184,7 +186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
184186 }
185187
186188 pub ( super ) fn lower_item_ref ( & mut self , i : & Item ) -> SmallVec < [ hir:: ItemId ; 1 ] > {
187- let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . resolver . local_def_id( i. id) } ] ;
189+ let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . local_def_id( i. id) } ] ;
188190 if let ItemKind :: Use ( ref use_tree) = & i. kind {
189191 self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
190192 }
@@ -200,7 +202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
200202 match tree. kind {
201203 UseTreeKind :: Nested ( ref nested_vec) => {
202204 for & ( ref nested, id) in nested_vec {
203- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
205+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
204206 self . lower_item_id_use_tree ( nested, id, vec) ;
205207 }
206208 }
@@ -209,7 +211,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
209211 for ( _, & id) in
210212 iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
211213 {
212- vec. push ( hir:: ItemId { def_id : self . resolver . local_def_id ( id) } ) ;
214+ vec. push ( hir:: ItemId { def_id : self . local_def_id ( id) } ) ;
213215 }
214216 }
215217 }
@@ -467,7 +469,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
467469 ) ,
468470 ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
469471 let body = P ( self . lower_mac_args ( body) ) ;
470- let macro_kind = self . resolver . decl_macro_kind ( self . resolver . local_def_id ( id) ) ;
472+ let macro_kind = self . resolver . decl_macro_kind ( self . local_def_id ( id) ) ;
471473 hir:: ItemKind :: Macro ( ast:: MacroDef { body, macro_rules } , macro_kind)
472474 }
473475 ItemKind :: MacCall ( ..) => {
@@ -528,7 +530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
528530 // Essentially a single `use` which imports two names is desugared into
529531 // two imports.
530532 for new_node_id in [ id1, id2] {
531- let new_id = self . resolver . local_def_id ( new_node_id) ;
533+ let new_id = self . local_def_id ( new_node_id) ;
532534 let Some ( res) = resolutions. next ( ) else {
533535 // Associate an HirId to both ids even if there is no resolution.
534536 let _old = self . children . insert (
@@ -541,7 +543,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
541543 let ident = * ident;
542544 let mut path = path. clone ( ) ;
543545 for seg in & mut path. segments {
544- seg. id = self . resolver . next_node_id ( ) ;
546+ seg. id = self . next_node_id ( ) ;
545547 }
546548 let span = path. span ;
547549
@@ -604,13 +606,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
604606
605607 // Add all the nested `PathListItem`s to the HIR.
606608 for & ( ref use_tree, id) in trees {
607- let new_hir_id = self . resolver . local_def_id ( id) ;
609+ let new_hir_id = self . local_def_id ( id) ;
608610
609611 let mut prefix = prefix. clone ( ) ;
610612
611613 // Give the segments new node-ids since they are being cloned.
612614 for seg in & mut prefix. segments {
613- seg. id = self . resolver . next_node_id ( ) ;
615+ seg. id = self . next_node_id ( ) ;
614616 }
615617
616618 // Each `use` import is an item and thus are owners of the
@@ -683,7 +685,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
683685
684686 fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef {
685687 hir:: ForeignItemRef {
686- id : hir:: ForeignItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
688+ id : hir:: ForeignItemId { def_id : self . local_def_id ( i. id ) } ,
687689 ident : self . lower_ident ( i. ident ) ,
688690 span : self . lower_span ( i. span ) ,
689691 }
@@ -838,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
838840 }
839841 AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
840842 } ;
841- let id = hir:: TraitItemId { def_id : self . resolver . local_def_id ( i. id ) } ;
843+ let id = hir:: TraitItemId { def_id : self . local_def_id ( i. id ) } ;
842844 let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
843845 hir:: TraitItemRef {
844846 id,
@@ -918,7 +920,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
918920 let has_value = true ;
919921 let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
920922 hir:: ImplItemRef {
921- id : hir:: ImplItemId { def_id : self . resolver . local_def_id ( i. id ) } ,
923+ id : hir:: ImplItemId { def_id : self . local_def_id ( i. id ) } ,
922924 ident : self . lower_ident ( i. ident ) ,
923925 span : self . lower_span ( i. span ) ,
924926 defaultness,
@@ -1321,7 +1323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13211323 generics
13221324 . params
13231325 . iter ( )
1324- . any ( |p| def_id == self . resolver . local_def_id ( p. id ) . to_def_id ( ) )
1326+ . any ( |p| def_id == self . local_def_id ( p. id ) . to_def_id ( ) )
13251327 }
13261328 // Either the `bounded_ty` is not a plain type parameter, or
13271329 // it's not found in the generic type parameters list.
0 commit comments