@@ -40,6 +40,7 @@ impl ItemLowerer<'_, '_, '_> {
40
40
41
41
impl < ' a > Visitor < ' a > for ItemLowerer < ' a , ' _ , ' _ > {
42
42
fn visit_item ( & mut self , item : & ' a Item ) {
43
+ self . lctx . allocate_hir_id_counter ( item. id ) ;
43
44
let hir_id = self . lctx . with_hir_id_owner ( item. id , |lctx| {
44
45
lctx. without_in_scope_lifetime_defs ( |lctx| {
45
46
let hir_item = lctx. lower_item ( item) ;
@@ -77,6 +78,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
77
78
}
78
79
79
80
fn visit_assoc_item ( & mut self , item : & ' a AssocItem , ctxt : AssocCtxt ) {
81
+ self . lctx . allocate_hir_id_counter ( item. id ) ;
80
82
self . lctx . with_hir_id_owner ( item. id , |lctx| match ctxt {
81
83
AssocCtxt :: Trait => {
82
84
let hir_item = lctx. lower_trait_item ( item) ;
@@ -154,41 +156,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
154
156
pub ( super ) fn lower_mod ( & mut self , items : & [ P < Item > ] , inner : Span ) -> hir:: Mod < ' hir > {
155
157
hir:: Mod {
156
158
inner : self . lower_span ( inner) ,
157
- item_ids : self . arena . alloc_from_iter ( items. iter ( ) . flat_map ( |x| self . lower_item_id ( x) ) ) ,
159
+ item_ids : self . arena . alloc_from_iter ( items. iter ( ) . flat_map ( |x| self . lower_item_ref ( x) ) ) ,
158
160
}
159
161
}
160
162
161
- pub ( super ) fn lower_item_id ( & mut self , i : & Item ) -> SmallVec < [ hir:: ItemId ; 1 ] > {
162
- let node_ids = match i. kind {
163
- ItemKind :: Use ( ref use_tree) => {
164
- let mut vec = smallvec ! [ i. id] ;
165
- self . lower_item_id_use_tree ( use_tree, i. id , & mut vec) ;
166
- vec
167
- }
168
- ItemKind :: Fn ( ..) | ItemKind :: Impl ( box ImplKind { of_trait : None , .. } ) => {
169
- smallvec ! [ i. id]
170
- }
171
- _ => smallvec ! [ i. id] ,
172
- } ;
173
-
163
+ pub ( super ) fn lower_item_ref ( & mut self , i : & Item ) -> SmallVec < [ hir:: ItemId ; 1 ] > {
164
+ let mut node_ids = smallvec ! [ hir:: ItemId { def_id: self . resolver. local_def_id( i. id) } ] ;
165
+ if let ItemKind :: Use ( ref use_tree) = & i. kind {
166
+ self . lower_item_id_use_tree ( use_tree, i. id , & mut node_ids) ;
167
+ }
174
168
node_ids
175
- . into_iter ( )
176
- . map ( |node_id| hir:: ItemId {
177
- def_id : self . allocate_hir_id_counter ( node_id) . expect_owner ( ) ,
178
- } )
179
- . collect ( )
180
169
}
181
170
182
171
fn lower_item_id_use_tree (
183
172
& mut self ,
184
173
tree : & UseTree ,
185
174
base_id : NodeId ,
186
- vec : & mut SmallVec < [ NodeId ; 1 ] > ,
175
+ vec : & mut SmallVec < [ hir :: ItemId ; 1 ] > ,
187
176
) {
188
177
match tree. kind {
189
178
UseTreeKind :: Nested ( ref nested_vec) => {
190
179
for & ( ref nested, id) in nested_vec {
191
- vec. push ( id ) ;
180
+ vec. push ( hir :: ItemId { def_id : self . resolver . local_def_id ( id ) } ) ;
192
181
self . lower_item_id_use_tree ( nested, id, vec) ;
193
182
}
194
183
}
@@ -197,7 +186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
197
186
for ( _, & id) in
198
187
iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , & [ id1, id2] )
199
188
{
200
- vec. push ( id ) ;
189
+ vec. push ( hir :: ItemId { def_id : self . resolver . local_def_id ( id ) } ) ;
201
190
}
202
191
}
203
192
}
@@ -700,7 +689,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
700
689
701
690
fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef < ' hir > {
702
691
hir:: ForeignItemRef {
703
- id : hir:: ForeignItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ,
692
+ id : hir:: ForeignItemId { def_id : self . allocate_hir_id_counter ( i. id ) } ,
704
693
ident : self . lower_ident ( i. ident ) ,
705
694
span : self . lower_span ( i. span ) ,
706
695
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
@@ -842,7 +831,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
842
831
}
843
832
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
844
833
} ;
845
- let id = hir:: TraitItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ;
834
+ let id = hir:: TraitItemId { def_id : self . resolver . local_def_id ( i. id ) } ;
846
835
let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
847
836
hir:: TraitItemRef {
848
837
id,
@@ -928,7 +917,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
928
917
let has_value = true ;
929
918
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
930
919
hir:: ImplItemRef {
931
- id : hir:: ImplItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ,
920
+ id : hir:: ImplItemId { def_id : self . allocate_hir_id_counter ( i. id ) } ,
932
921
ident : self . lower_ident ( i. ident ) ,
933
922
span : self . lower_span ( i. span ) ,
934
923
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
0 commit comments