@@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> {
3535
3636impl < ' a > Visitor < ' a > for ItemLowerer < ' a , ' _ , ' _ > {
3737 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 ( ) ;
3939
4040 self . lctx . modules . insert (
41- hir_id ,
41+ def_id ,
4242 hir:: ModuleItems {
4343 items : BTreeSet :: new ( ) ,
4444 trait_items : BTreeSet :: new ( ) ,
@@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
4848 ) ;
4949
5050 let old = self . lctx . current_module ;
51- self . lctx . current_module = hir_id ;
51+ self . lctx . current_module = def_id ;
5252 visit:: walk_mod ( self , m) ;
5353 self . lctx . current_module = old;
5454 }
@@ -58,8 +58,8 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
5858 self . lctx . with_hir_id_owner ( item. id , |lctx| {
5959 lctx. without_in_scope_lifetime_defs ( |lctx| {
6060 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 ) ;
6363 }
6464 } )
6565 } ) ;
@@ -92,13 +92,13 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
9292 self . lctx . with_hir_id_owner ( item. id , |lctx| match ctxt {
9393 AssocCtxt :: Trait => {
9494 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 ( ) ;
9696 lctx. trait_items . insert ( id, hir_item) ;
9797 lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . trait_items . insert ( id) ;
9898 }
9999 AssocCtxt :: Impl => {
100100 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 ( ) ;
102102 lctx. impl_items . insert ( id, hir_item) ;
103103 lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . impl_items . insert ( id) ;
104104 }
@@ -111,7 +111,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
111111 self . lctx . allocate_hir_id_counter ( item. id ) ;
112112 self . lctx . with_hir_id_owner ( item. id , |lctx| {
113113 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 ( ) ;
115115 lctx. foreign_items . insert ( id, hir_item) ;
116116 lctx. modules . get_mut ( & lctx. current_module ) . unwrap ( ) . foreign_items . insert ( id) ;
117117 } ) ;
@@ -128,7 +128,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
128128 // only used when lowering a child item of a trait or impl.
129129 fn with_parent_item_lifetime_defs < T > (
130130 & mut self ,
131- parent_hir_id : hir:: HirId ,
131+ parent_hir_id : hir:: ItemId ,
132132 f : impl FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
133133 ) -> T {
134134 let old_len = self . in_scope_lifetimes . len ( ) ;
@@ -197,7 +197,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
197197
198198 node_ids
199199 . 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+ } )
201203 . collect ( )
202204 }
203205
@@ -232,13 +234,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
232234
233235 if let ItemKind :: MacroDef ( MacroDef { ref body, macro_rules } ) = i. kind {
234236 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 ( ) ;
236238 let body = P ( self . lower_mac_args ( body) ) ;
237239 self . exported_macros . push ( hir:: MacroDef {
238240 ident,
239241 vis,
240242 attrs,
241- hir_id ,
243+ def_id ,
242244 span : i. span ,
243245 ast : MacroDef { body, macro_rules } ,
244246 } ) ;
@@ -250,7 +252,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
250252
251253 let kind = self . lower_item_kind ( i. span , i. id , & mut ident, attrs, & mut vis, & i. kind ) ;
252254
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+ } )
254263 }
255264
256265 fn lower_item_kind (
@@ -387,8 +396,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
387396 self_ty : ref ty,
388397 items : ref impl_items,
389398 } ) => {
390- let def_id = self . resolver . local_def_id ( id) ;
391-
392399 // Lower the "impl header" first. This ordering is important
393400 // for in-band lifetimes! Consider `'a` here:
394401 //
@@ -402,10 +409,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
402409 // method, it will not be considered an in-band
403410 // lifetime to be added, but rather a reference to a
404411 // 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 ( ) ;
406413 let ( generics, ( trait_ref, lowered_ty) ) = self . add_in_band_defs (
407414 ast_generics,
408- def_id ,
415+ lowered_trait_def_id ,
409416 AnonymousLifetimeMode :: CreateParameter ,
410417 |this, _| {
411418 let trait_ref = trait_ref. as_ref ( ) . map ( |trait_ref| {
@@ -417,7 +424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
417424 this. trait_impls
418425 . entry ( def_id)
419426 . or_default ( )
420- . push ( lowered_trait_impl_id ) ;
427+ . push ( lowered_trait_def_id ) ;
421428 }
422429 }
423430
@@ -557,7 +564,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
557564 let vis = this. rebuild_vis ( & vis) ;
558565
559566 this. insert_item ( hir:: Item {
560- hir_id : new_id,
567+ def_id : new_id. expect_owner ( ) ,
561568 ident,
562569 attrs,
563570 kind,
@@ -629,7 +636,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
629636 this. lower_use_tree ( use_tree, & prefix, id, & mut vis, & mut ident, attrs) ;
630637
631638 this. insert_item ( hir:: Item {
632- hir_id : new_hir_id,
639+ def_id : new_hir_id. expect_owner ( ) ,
633640 ident,
634641 attrs,
635642 kind,
@@ -702,7 +709,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
702709 fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem < ' hir > {
703710 let def_id = self . resolver . local_def_id ( i. id ) ;
704711 hir:: ForeignItem {
705- hir_id : self . lower_node_id ( i . id ) ,
712+ def_id ,
706713 ident : i. ident ,
707714 attrs : self . lower_attrs ( & i. attrs ) ,
708715 kind : match i. kind {
@@ -737,7 +744,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
737744
738745 fn lower_foreign_item_ref ( & mut self , i : & ForeignItem ) -> hir:: ForeignItemRef < ' hir > {
739746 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 ( ) } ,
741748 ident : i. ident ,
742749 span : i. span ,
743750 vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
@@ -837,7 +844,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
837844 } ;
838845
839846 hir:: TraitItem {
840- hir_id : self . lower_node_id ( i . id ) ,
847+ def_id : trait_item_def_id ,
841848 ident : i. ident ,
842849 attrs : self . lower_attrs ( & i. attrs ) ,
843850 generics,
@@ -857,7 +864,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
857864 }
858865 AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
859866 } ;
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 ( ) } ;
861868 let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
862869 hir:: TraitItemRef { id, ident : i. ident , span : i. span , defaultness, kind }
863870 }
@@ -922,7 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
922929 let has_value = true ;
923930 let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
924931 hir:: ImplItem {
925- hir_id : self . lower_node_id ( i. id ) ,
932+ def_id : self . lower_node_id ( i. id ) . expect_owner ( ) ,
926933 ident : i. ident ,
927934 attrs : self . lower_attrs ( & i. attrs ) ,
928935 generics,
@@ -938,7 +945,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
938945 let has_value = true ;
939946 let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
940947 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 ( ) } ,
942949 ident : i. ident ,
943950 span : i. span ,
944951 vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
0 commit comments