@@ -62,6 +62,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
62
62
owner : NodeId ,
63
63
f : impl FnOnce ( & mut LoweringContext < ' _ , ' hir > ) -> hir:: OwnerNode < ' hir > ,
64
64
) {
65
+ let next_node_id = self . resolver . next_node_id ;
65
66
let mut lctx = LoweringContext {
66
67
// Pseudo-globals.
67
68
sess : & self . sess ,
@@ -79,6 +80,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
79
80
node_id_to_local_id : Default :: default ( ) ,
80
81
local_id_to_def_id : SortedMap :: new ( ) ,
81
82
trait_map : Default :: default ( ) ,
83
+ local_node_id_to_def_id : FxHashMap :: default ( ) ,
84
+ next_node_id,
82
85
83
86
// Lowering state.
84
87
catch_scope : None ,
@@ -126,8 +129,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
126
129
127
130
#[ instrument( level = "debug" , skip( self , c) ) ]
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 ) ;
@@ -141,7 +143,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
141
143
}
142
144
143
145
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 ] ;
145
147
146
148
let parent_id = {
147
149
let parent = self . definitions . def_key ( def_id) . parent ;
@@ -185,7 +187,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
185
187
}
186
188
187
189
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) } ] ;
189
191
if let ItemKind :: Use ( ref use_tree) = & i. kind {
190
192
self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
191
193
}
@@ -201,7 +203,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
201
203
match tree. kind {
202
204
UseTreeKind :: Nested ( ref nested_vec) => {
203
205
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) } ) ;
205
207
self . lower_item_id_use_tree ( nested, id, vec) ;
206
208
}
207
209
}
@@ -210,7 +212,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
210
212
for ( _, & id) in
211
213
iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
212
214
{
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) } ) ;
214
216
}
215
217
}
216
218
}
@@ -475,7 +477,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
475
477
}
476
478
ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) => {
477
479
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) ) ;
479
481
hir:: ItemKind :: Macro ( ast:: MacroDef { body, macro_rules } , macro_kind)
480
482
}
481
483
ItemKind :: MacCall ( ..) => {
@@ -535,7 +537,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
535
537
// Essentially a single `use` which imports two names is desugared into
536
538
// two imports.
537
539
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) ;
539
541
let Some ( res) = resolutions. next ( ) else {
540
542
// Associate an HirId to both ids even if there is no resolution.
541
543
let _old = self . children . insert (
@@ -548,7 +550,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
548
550
let ident = * ident;
549
551
let mut path = path. clone ( ) ;
550
552
for seg in & mut path. segments {
551
- seg. id = self . resolver . next_node_id ( ) ;
553
+ seg. id = self . next_node_id ( ) ;
552
554
}
553
555
let span = path. span ;
554
556
@@ -611,13 +613,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
611
613
612
614
// Add all the nested `PathListItem`s to the HIR.
613
615
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) ;
615
617
616
618
let mut prefix = prefix. clone ( ) ;
617
619
618
620
// Give the segments new node-ids since they are being cloned.
619
621
for seg in & mut prefix. segments {
620
- seg. id = self . resolver . next_node_id ( ) ;
622
+ seg. id = self . next_node_id ( ) ;
621
623
}
622
624
623
625
// Each `use` import is an item and thus are owners of the
@@ -691,7 +693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
691
693
692
694
fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef {
693
695
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 ) } ,
695
697
ident : self . lower_ident ( i. ident ) ,
696
698
span : self . lower_span ( i. span ) ,
697
699
}
@@ -847,7 +849,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
847
849
}
848
850
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
849
851
} ;
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 ) } ;
851
853
let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
852
854
hir:: TraitItemRef {
853
855
id,
@@ -927,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
927
929
let has_value = true ;
928
930
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
929
931
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 ) } ,
931
933
ident : self . lower_ident ( i. ident ) ,
932
934
span : self . lower_span ( i. span ) ,
933
935
defaultness,
@@ -1339,7 +1341,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1339
1341
generics
1340
1342
. params
1341
1343
. 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 ( ) )
1343
1345
}
1344
1346
// Either the `bounded_ty` is not a plain type parameter, or
1345
1347
// it's not found in the generic type parameters list.
@@ -1443,7 +1445,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1443
1445
match kind {
1444
1446
GenericParamKind :: Const { .. } => None ,
1445
1447
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 ( ) ;
1447
1449
let ty_path = self . arena . alloc ( hir:: Path {
1448
1450
span : param_span,
1449
1451
res : Res :: Def ( DefKind :: TyParam , def_id) ,
@@ -1466,7 +1468,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1466
1468
let res = self . resolver . get_lifetime_res ( id) . unwrap_or_else ( || {
1467
1469
panic ! ( "Missing resolution for lifetime {:?} at {:?}" , id, ident. span)
1468
1470
} ) ;
1469
- let lt_id = self . resolver . next_node_id ( ) ;
1471
+ let lt_id = self . next_node_id ( ) ;
1470
1472
let lifetime = self . new_named_lifetime_with_res ( lt_id, ident_span, ident, res) ;
1471
1473
Some ( hir:: WherePredicate :: RegionPredicate ( hir:: WhereRegionPredicate {
1472
1474
lifetime,
0 commit comments