@@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> {
35
35
36
36
impl < ' a > Visitor < ' a > for ItemLowerer < ' a , ' _ , ' _ > {
37
37
fn visit_mod ( & mut self , m : & ' a Mod , _s : Span , _attrs : & [ Attribute ] , n : NodeId ) {
38
- let hir_id = self . lctx . lower_node_id ( n) ;
38
+ let def_id = self . lctx . lower_node_id ( n) . expect_owner ( ) ;
39
39
40
40
self . lctx . modules . insert (
41
- hir_id ,
41
+ def_id ,
42
42
hir:: ModuleItems {
43
43
items : BTreeSet :: new ( ) ,
44
44
trait_items : BTreeSet :: new ( ) ,
@@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
48
48
) ;
49
49
50
50
let old = self . lctx . current_module ;
51
- self . lctx . current_module = hir_id ;
51
+ self . lctx . current_module = def_id ;
52
52
visit:: walk_mod ( self , m) ;
53
53
self . lctx . current_module = old;
54
54
}
@@ -58,8 +58,8 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
58
58
self . lctx . with_hir_id_owner ( item. id , |lctx| {
59
59
lctx. without_in_scope_lifetime_defs ( |lctx| {
60
60
if let Some ( hir_item) = lctx. lower_item ( item) {
61
- item_hir_id = Some ( hir_item. hir_id ) ;
62
- lctx . insert_item ( hir_item ) ;
61
+ let id = lctx . insert_item ( hir_item) ;
62
+ item_hir_id = Some ( id ) ;
63
63
}
64
64
} )
65
65
} ) ;
@@ -92,13 +92,13 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
92
92
self . lctx . with_hir_id_owner ( item. id , |lctx| match ctxt {
93
93
AssocCtxt :: Trait => {
94
94
let hir_item = lctx. lower_trait_item ( item) ;
95
- let id = hir :: TraitItemId { hir_id : hir_item. hir_id } ;
95
+ let id = hir_item. trait_item_id ( ) ;
96
96
lctx. trait_items . insert ( id, hir_item) ;
97
97
lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . trait_items . insert ( id) ;
98
98
}
99
99
AssocCtxt :: Impl => {
100
100
let hir_item = lctx. lower_impl_item ( item) ;
101
- let id = hir :: ImplItemId { hir_id : hir_item. hir_id } ;
101
+ let id = hir_item. impl_item_id ( ) ;
102
102
lctx. impl_items . insert ( id, hir_item) ;
103
103
lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . impl_items . insert ( id) ;
104
104
}
@@ -111,7 +111,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
111
111
self . lctx . allocate_hir_id_counter ( item. id ) ;
112
112
self . lctx . with_hir_id_owner ( item. id , |lctx| {
113
113
let hir_item = lctx. lower_foreign_item ( item) ;
114
- let id = hir :: ForeignItemId { hir_id : hir_item. hir_id } ;
114
+ let id = hir_item. foreign_item_id ( ) ;
115
115
lctx. foreign_items . insert ( id, hir_item) ;
116
116
lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . foreign_items . insert ( id) ;
117
117
} ) ;
@@ -128,7 +128,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
128
128
// only used when lowering a child item of a trait or impl.
129
129
fn with_parent_item_lifetime_defs < T > (
130
130
& mut self ,
131
- parent_hir_id : hir:: HirId ,
131
+ parent_hir_id : hir:: ItemId ,
132
132
f : impl FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
133
133
) -> T {
134
134
let old_len = self . in_scope_lifetimes . len ( ) ;
@@ -197,7 +197,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
197
197
198
198
node_ids
199
199
. into_iter ( )
200
- . map ( |node_id| hir:: ItemId { id : self . allocate_hir_id_counter ( node_id) } )
200
+ . map ( |node_id| hir:: ItemId {
201
+ def_id : self . allocate_hir_id_counter ( node_id) . expect_owner ( ) ,
202
+ } )
201
203
. collect ( )
202
204
}
203
205
@@ -232,13 +234,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
232
234
233
235
if let ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) = i. kind {
234
236
if !macro_rules || self . sess . contains_name ( & i. attrs , sym:: macro_export) {
235
- let hir_id = self . lower_node_id ( i. id ) ;
237
+ let def_id = self . lower_node_id ( i. id ) . expect_owner ( ) ;
236
238
let body = P ( self . lower_mac_args ( body) ) ;
237
239
self . exported_macros . push ( hir:: MacroDef {
238
240
ident,
239
241
vis,
240
242
attrs,
241
- hir_id ,
243
+ def_id ,
242
244
span : i. span ,
243
245
ast : MacroDef { body, macro_rules } ,
244
246
} ) ;
@@ -250,7 +252,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
250
252
251
253
let kind = self . lower_item_kind ( i. span , i. id , & mut ident, attrs, & mut vis, & i. kind ) ;
252
254
253
- Some ( hir:: Item { hir_id : self . lower_node_id ( i. id ) , ident, attrs, kind, vis, span : i. span } )
255
+ Some ( hir:: Item {
256
+ def_id : self . lower_node_id ( i. id ) . expect_owner ( ) ,
257
+ ident,
258
+ attrs,
259
+ kind,
260
+ vis,
261
+ span : i. span ,
262
+ } )
254
263
}
255
264
256
265
fn lower_item_kind (
@@ -387,8 +396,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
387
396
self_ty : ref ty,
388
397
items : ref impl_items,
389
398
} ) => {
390
- let def_id = self . resolver . local_def_id ( id) ;
391
-
392
399
// Lower the "impl header" first. This ordering is important
393
400
// for in-band lifetimes! Consider `'a` here:
394
401
//
@@ -402,10 +409,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
402
409
// method, it will not be considered an in-band
403
410
// lifetime to be added, but rather a reference to a
404
411
// parent lifetime.
405
- let lowered_trait_impl_id = self . lower_node_id ( id) ;
412
+ let lowered_trait_def_id = self . lower_node_id ( id) . expect_owner ( ) ;
406
413
let ( generics, ( trait_ref, lowered_ty) ) = self . add_in_band_defs (
407
414
ast_generics,
408
- def_id ,
415
+ lowered_trait_def_id ,
409
416
AnonymousLifetimeMode :: CreateParameter ,
410
417
|this, _| {
411
418
let trait_ref = trait_ref. as_ref ( ) . map ( |trait_ref| {
@@ -417,7 +424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
417
424
this. trait_impls
418
425
. entry ( def_id)
419
426
. or_default ( )
420
- . push ( lowered_trait_impl_id ) ;
427
+ . push ( lowered_trait_def_id ) ;
421
428
}
422
429
}
423
430
@@ -557,7 +564,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
557
564
let vis = this. rebuild_vis ( & vis) ;
558
565
559
566
this. insert_item ( hir:: Item {
560
- hir_id : new_id,
567
+ def_id : new_id. expect_owner ( ) ,
561
568
ident,
562
569
attrs,
563
570
kind,
@@ -629,7 +636,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
629
636
this. lower_use_tree ( use_tree, & prefix, id, & mut vis, & mut ident, attrs) ;
630
637
631
638
this. insert_item ( hir:: Item {
632
- hir_id : new_hir_id,
639
+ def_id : new_hir_id. expect_owner ( ) ,
633
640
ident,
634
641
attrs,
635
642
kind,
@@ -702,7 +709,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
702
709
fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem < ' hir > {
703
710
let def_id = self . resolver . local_def_id ( i. id ) ;
704
711
hir:: ForeignItem {
705
- hir_id : self . lower_node_id ( i . id ) ,
712
+ def_id ,
706
713
ident : i. ident ,
707
714
attrs : self . lower_attrs ( & i. attrs ) ,
708
715
kind : match i. kind {
@@ -737,7 +744,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
737
744
738
745
fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef < ' hir > {
739
746
hir:: ForeignItemRef {
740
- id : hir:: ForeignItemId { hir_id : self . lower_node_id ( i. id ) } ,
747
+ id : hir:: ForeignItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ,
741
748
ident : i. ident ,
742
749
span : i. span ,
743
750
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
@@ -837,7 +844,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
837
844
} ;
838
845
839
846
hir:: TraitItem {
840
- hir_id : self . lower_node_id ( i . id ) ,
847
+ def_id : trait_item_def_id ,
841
848
ident : i. ident ,
842
849
attrs : self . lower_attrs ( & i. attrs ) ,
843
850
generics,
@@ -857,7 +864,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
857
864
}
858
865
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
859
866
} ;
860
- let id = hir:: TraitItemId { hir_id : self . lower_node_id ( i. id ) } ;
867
+ let id = hir:: TraitItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ;
861
868
let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
862
869
hir:: TraitItemRef { id, ident : i. ident , span : i. span , defaultness, kind }
863
870
}
@@ -922,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
922
929
let has_value = true ;
923
930
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
924
931
hir:: ImplItem {
925
- hir_id : self . lower_node_id ( i. id ) ,
932
+ def_id : self . lower_node_id ( i. id ) . expect_owner ( ) ,
926
933
ident : i. ident ,
927
934
attrs : self . lower_attrs ( & i. attrs ) ,
928
935
generics,
@@ -938,7 +945,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
938
945
let has_value = true ;
939
946
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
940
947
hir:: ImplItemRef {
941
- id : hir:: ImplItemId { hir_id : self . lower_node_id ( i. id ) } ,
948
+ id : hir:: ImplItemId { def_id : self . lower_node_id ( i. id ) . expect_owner ( ) } ,
942
949
ident : i. ident ,
943
950
span : i. span ,
944
951
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
0 commit comments