@@ -138,10 +138,10 @@ struct LoweringContext<'a, 'hir> {
138
138
impl_trait_defs : Vec < hir:: GenericParam < ' hir > > ,
139
139
impl_trait_bounds : Vec < hir:: WherePredicate < ' hir > > ,
140
140
141
- /// NodeIds of labelled nodes that are lowered inside the current HIR owner.
142
- labelled_node_id_to_local_id : NodeMap < hir:: ItemLocalId > ,
143
- /// NodeIds of identifier that are lowered inside the current HIR owner.
144
- ident_to_local_id : NodeMap < hir:: ItemLocalId > ,
141
+ /// NodeIds of pattern identifiers and labelled nodes that are lowered inside the current HIR owner.
142
+ ident_and_label_to_local_id : NodeMap < hir:: ItemLocalId > ,
143
+ /// NodeIds that are lowered inside the current HIR owner. Only used for duplicate lowering check .
144
+ node_id_to_local_id : NodeMap < hir:: ItemLocalId > ,
145
145
146
146
allow_try_trait : Lrc < [ Symbol ] > ,
147
147
allow_gen_future : Lrc < [ Symbol ] > ,
@@ -178,8 +178,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
178
178
current_hir_id_owner : hir:: CRATE_OWNER_ID ,
179
179
current_def_id_parent : CRATE_DEF_ID ,
180
180
item_local_id_counter : hir:: ItemLocalId :: ZERO ,
181
- labelled_node_id_to_local_id : Default :: default ( ) ,
182
- ident_to_local_id : Default :: default ( ) ,
181
+ ident_and_label_to_local_id : Default :: default ( ) ,
182
+ node_id_to_local_id : Default :: default ( ) ,
183
183
trait_map : Default :: default ( ) ,
184
184
185
185
// Lowering state.
@@ -589,9 +589,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
589
589
590
590
let current_attrs = std:: mem:: take ( & mut self . attrs ) ;
591
591
let current_bodies = std:: mem:: take ( & mut self . bodies ) ;
592
- let current_labelled_node_id_to_local_id =
593
- std:: mem:: take ( & mut self . labelled_node_id_to_local_id ) ;
594
- let current_ident_to_local_id = std:: mem:: take ( & mut self . ident_to_local_id ) ;
592
+ let current_ident_and_label_to_local_id =
593
+ std:: mem:: take ( & mut self . ident_and_label_to_local_id ) ;
594
+ let current_node_id_to_local_id = std:: mem:: take ( & mut self . node_id_to_local_id ) ;
595
595
let current_trait_map = std:: mem:: take ( & mut self . trait_map ) ;
596
596
let current_owner =
597
597
std:: mem:: replace ( & mut self . current_hir_id_owner , hir:: OwnerId { def_id } ) ;
@@ -604,6 +604,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
604
604
// we want `f` to be able to refer to the `LocalDefId`s that the caller created.
605
605
// and the caller to refer to some of the subdefinitions' nodes' `LocalDefId`s.
606
606
607
+ // Always allocate the first `HirId` for the owner itself.
608
+ let _old = self . node_id_to_local_id . insert ( owner, hir:: ItemLocalId :: ZERO ) ;
609
+ debug_assert_eq ! ( _old, None ) ;
610
+
607
611
let item = self . with_def_id_parent ( def_id, f) ;
608
612
debug_assert_eq ! ( def_id, item. def_id( ) . def_id) ;
609
613
// `f` should have consumed all the elements in these vectors when constructing `item`.
@@ -613,8 +617,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
613
617
614
618
self . attrs = current_attrs;
615
619
self . bodies = current_bodies;
616
- self . labelled_node_id_to_local_id = current_labelled_node_id_to_local_id ;
617
- self . ident_to_local_id = current_ident_to_local_id ;
620
+ self . ident_and_label_to_local_id = current_ident_and_label_to_local_id ;
621
+ self . node_id_to_local_id = current_node_id_to_local_id ;
618
622
self . trait_map = current_trait_map;
619
623
self . current_hir_id_owner = current_owner;
620
624
self . item_local_id_counter = current_local_counter;
@@ -703,6 +707,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
703
707
self . trait_map . insert ( hir_id. local_id , traits. into_boxed_slice ( ) ) ;
704
708
}
705
709
710
+ // Check whether the same `NodeId` is lowered more than once.
711
+ #[ cfg( debug_assertions) ]
712
+ {
713
+ let old = self . node_id_to_local_id . insert ( ast_node_id, local_id) ;
714
+ assert_eq ! ( old, None ) ;
715
+ }
716
+
706
717
hir_id
707
718
}
708
719
@@ -720,7 +731,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
720
731
fn lower_res ( & mut self , res : Res < NodeId > ) -> Res {
721
732
let res: Result < Res , ( ) > = res. apply_id ( |id| {
722
733
let owner = self . current_hir_id_owner ;
723
- let local_id = self . ident_to_local_id . get ( & id) . copied ( ) . ok_or ( ( ) ) ?;
734
+ let local_id = self . ident_and_label_to_local_id . get ( & id) . copied ( ) . ok_or ( ( ) ) ?;
724
735
Ok ( HirId { owner, local_id } )
725
736
} ) ;
726
737
trace ! ( ?res) ;
0 commit comments