@@ -64,6 +64,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
64
64
owner : NodeId ,
65
65
f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
66
66
) {
67
+ let next_node_id = self . resolver . next_node_id ;
67
68
let mut lctx = LoweringContext {
68
69
// Pseudo-globals.
69
70
sess : & self . sess ,
@@ -82,6 +83,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
82
83
node_id_to_local_id : Default :: default ( ) ,
83
84
local_id_to_def_id : SortedMap :: new ( ) ,
84
85
trait_map : Default :: default ( ) ,
86
+ local_node_id_to_def_id : FxHashMap :: default ( ) ,
87
+ next_node_id,
85
88
86
89
// Lowering state.
87
90
catch_scope : None ,
@@ -126,8 +129,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
126
129
}
127
130
128
131
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 ) ;
131
133
self . with_lctx ( CRATE_NODE_ID , |lctx| {
132
134
let module = lctx. lower_mod ( & c. items , & c. spans ) ;
133
135
lctx. lower_attrs ( hir:: CRATE_HIR_ID , & c. attrs ) ;
@@ -140,7 +142,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
140
142
}
141
143
142
144
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 ] ;
144
146
145
147
let parent_id = {
146
148
let parent = self . definitions . def_key ( def_id) . parent ;
@@ -184,7 +186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
184
186
}
185
187
186
188
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) } ] ;
188
190
if let ItemKind :: Use ( ref use_tree) = & i. kind {
189
191
self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
190
192
}
@@ -200,7 +202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
200
202
match tree. kind {
201
203
UseTreeKind :: Nested ( ref nested_vec) => {
202
204
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) } ) ;
204
206
self . lower_item_id_use_tree ( nested, id, vec) ;
205
207
}
206
208
}
@@ -209,7 +211,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
209
211
for ( _, & id) in
210
212
iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
211
213
{
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) } ) ;
213
215
}
214
216
}
215
217
}
@@ -467,7 +469,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
467
469
) ,
468
470
ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
469
471
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) ) ;
471
473
hir:: ItemKind :: Macro ( ast:: MacroDef { body, macro_rules } , macro_kind)
472
474
}
473
475
ItemKind :: MacCall ( ..) => {
@@ -528,7 +530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
528
530
// Essentially a single `use` which imports two names is desugared into
529
531
// two imports.
530
532
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) ;
532
534
let Some ( res) = resolutions. next ( ) else {
533
535
// Associate an HirId to both ids even if there is no resolution.
534
536
let _old = self . children . insert (
@@ -541,7 +543,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
541
543
let ident = * ident;
542
544
let mut path = path. clone ( ) ;
543
545
for seg in & mut path. segments {
544
- seg. id = self . resolver . next_node_id ( ) ;
546
+ seg. id = self . next_node_id ( ) ;
545
547
}
546
548
let span = path. span ;
547
549
@@ -604,13 +606,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
604
606
605
607
// Add all the nested `PathListItem`s to the HIR.
606
608
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) ;
608
610
609
611
let mut prefix = prefix. clone ( ) ;
610
612
611
613
// Give the segments new node-ids since they are being cloned.
612
614
for seg in & mut prefix. segments {
613
- seg. id = self . resolver . next_node_id ( ) ;
615
+ seg. id = self . next_node_id ( ) ;
614
616
}
615
617
616
618
// Each `use` import is an item and thus are owners of the
@@ -683,7 +685,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
683
685
684
686
fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef {
685
687
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 ) } ,
687
689
ident : self . lower_ident ( i. ident ) ,
688
690
span : self . lower_span ( i. span ) ,
689
691
}
@@ -838,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
838
840
}
839
841
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
840
842
} ;
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 ) } ;
842
844
let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
843
845
hir:: TraitItemRef {
844
846
id,
@@ -918,7 +920,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
918
920
let has_value = true ;
919
921
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
920
922
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 ) } ,
922
924
ident : self . lower_ident ( i. ident ) ,
923
925
span : self . lower_span ( i. span ) ,
924
926
defaultness,
@@ -1321,7 +1323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1321
1323
generics
1322
1324
. params
1323
1325
. 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 ( ) )
1325
1327
}
1326
1328
// Either the `bounded_ty` is not a plain type parameter, or
1327
1329
// it's not found in the generic type parameters list.
0 commit comments