@@ -165,7 +165,7 @@ struct LoweringContext<'a, 'hir: 'a> {
165
165
166
166
type_def_lifetime_params : DefIdMap < usize > ,
167
167
168
- current_hir_id_owner : Vec < ( LocalDefId , u32 ) > ,
168
+ current_hir_id_owner : ( LocalDefId , u32 ) ,
169
169
item_local_id_counters : NodeMap < u32 > ,
170
170
node_id_to_hir_id : IndexVec < NodeId , Option < hir:: HirId > > ,
171
171
@@ -321,7 +321,7 @@ pub fn lower_crate<'a, 'hir>(
321
321
anonymous_lifetime_mode : AnonymousLifetimeMode :: PassThrough ,
322
322
type_def_lifetime_params : Default :: default ( ) ,
323
323
current_module : CRATE_DEF_ID ,
324
- current_hir_id_owner : vec ! [ ( CRATE_DEF_ID , 0 ) ] ,
324
+ current_hir_id_owner : ( CRATE_DEF_ID , 0 ) ,
325
325
item_local_id_counters : Default :: default ( ) ,
326
326
node_id_to_hir_id : IndexVec :: new ( ) ,
327
327
generator_kind : None ,
@@ -594,9 +594,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
594
594
. insert ( owner, HIR_ID_COUNTER_LOCKED )
595
595
. unwrap_or_else ( || panic ! ( "no `item_local_id_counters` entry for {:?}" , owner) ) ;
596
596
let def_id = self . resolver . local_def_id ( owner) ;
597
- self . current_hir_id_owner . push ( ( def_id, counter) ) ;
597
+ let old_owner = std :: mem :: replace ( & mut self . current_hir_id_owner , ( def_id, counter) ) ;
598
598
let ret = f ( self ) ;
599
- let ( new_def_id, new_counter) = self . current_hir_id_owner . pop ( ) . unwrap ( ) ;
599
+ let ( new_def_id, new_counter) =
600
+ std:: mem:: replace ( & mut self . current_hir_id_owner , old_owner) ;
600
601
601
602
debug_assert ! ( def_id == new_def_id) ;
602
603
debug_assert ! ( new_counter >= counter) ;
@@ -614,8 +615,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
614
615
/// properly. Calling the method twice with the same `NodeId` is fine though.
615
616
fn lower_node_id ( & mut self , ast_node_id : NodeId ) -> hir:: HirId {
616
617
self . lower_node_id_generic ( ast_node_id, |this| {
617
- let & mut ( owner, ref mut local_id_counter) =
618
- this. current_hir_id_owner . last_mut ( ) . unwrap ( ) ;
618
+ let & mut ( owner, ref mut local_id_counter) = & mut this. current_hir_id_owner ;
619
619
let local_id = * local_id_counter;
620
620
* local_id_counter += 1 ;
621
621
hir:: HirId { owner, local_id : hir:: ItemLocalId :: from_u32 ( local_id) }
@@ -868,10 +868,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
868
868
// wouldn't have been added yet.
869
869
let generics = this. lower_generics_mut (
870
870
generics,
871
- ImplTraitContext :: Universal (
872
- & mut params,
873
- this. current_hir_id_owner . last ( ) . unwrap ( ) . 0 ,
874
- ) ,
871
+ ImplTraitContext :: Universal ( & mut params, this. current_hir_id_owner . 0 ) ,
875
872
) ;
876
873
let res = f ( this, & mut params) ;
877
874
( params, ( generics, res) )
@@ -1077,7 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1077
1074
}
1078
1075
AssocTyConstraintKind :: Bound { ref bounds } => {
1079
1076
let mut capturable_lifetimes;
1080
- let mut parent_def_id = self . current_hir_id_owner . last ( ) . unwrap ( ) . 0 ;
1077
+ let mut parent_def_id = self . current_hir_id_owner . 0 ;
1081
1078
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1082
1079
let ( desugar_to_impl_trait, itctx) = match itctx {
1083
1080
// We are in the return position:
@@ -1198,7 +1195,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1198
1195
1199
1196
// Construct a AnonConst where the expr is the "ty"'s path.
1200
1197
1201
- let parent_def_id = self . current_hir_id_owner . last ( ) . unwrap ( ) . 0 ;
1198
+ let parent_def_id = self . current_hir_id_owner . 0 ;
1202
1199
let node_id = self . resolver . next_node_id ( ) ;
1203
1200
1204
1201
// Add a definition for the in-band const def.
@@ -1814,10 +1811,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1814
1811
if let Some ( ( _, ibty) ) = & mut in_band_ty_params {
1815
1812
this. lower_ty_direct (
1816
1813
& param. ty ,
1817
- ImplTraitContext :: Universal (
1818
- ibty,
1819
- this. current_hir_id_owner . last ( ) . unwrap ( ) . 0 ,
1820
- ) ,
1814
+ ImplTraitContext :: Universal ( ibty, this. current_hir_id_owner . 0 ) ,
1821
1815
)
1822
1816
} else {
1823
1817
this. lower_ty_direct ( & param. ty , ImplTraitContext :: disallowed ( ) )
0 commit comments