@@ -165,7 +165,7 @@ struct LoweringContext<'a, 'hir: 'a> {
165165
166166 type_def_lifetime_params : DefIdMap < usize > ,
167167
168- current_hir_id_owner : Vec < ( LocalDefId , u32 ) > ,
168+ current_hir_id_owner : ( LocalDefId , u32 ) ,
169169 item_local_id_counters : NodeMap < u32 > ,
170170 node_id_to_hir_id : IndexVec < NodeId , Option < hir:: HirId > > ,
171171
@@ -321,7 +321,7 @@ pub fn lower_crate<'a, 'hir>(
321321 anonymous_lifetime_mode : AnonymousLifetimeMode :: PassThrough ,
322322 type_def_lifetime_params : Default :: default ( ) ,
323323 current_module : CRATE_DEF_ID ,
324- current_hir_id_owner : vec ! [ ( CRATE_DEF_ID , 0 ) ] ,
324+ current_hir_id_owner : ( CRATE_DEF_ID , 0 ) ,
325325 item_local_id_counters : Default :: default ( ) ,
326326 node_id_to_hir_id : IndexVec :: new ( ) ,
327327 generator_kind : None ,
@@ -594,9 +594,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
594594 . insert ( owner, HIR_ID_COUNTER_LOCKED )
595595 . unwrap_or_else ( || panic ! ( "no `item_local_id_counters` entry for {:?}" , owner) ) ;
596596 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) ) ;
598598 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) ;
600601
601602 debug_assert ! ( def_id == new_def_id) ;
602603 debug_assert ! ( new_counter >= counter) ;
@@ -614,8 +615,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
614615 /// properly. Calling the method twice with the same `NodeId` is fine though.
615616 fn lower_node_id ( & mut self , ast_node_id : NodeId ) -> hir:: HirId {
616617 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 ;
619619 let local_id = * local_id_counter;
620620 * local_id_counter += 1 ;
621621 hir:: HirId { owner, local_id : hir:: ItemLocalId :: from_u32 ( local_id) }
@@ -868,10 +868,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
868868 // wouldn't have been added yet.
869869 let generics = this. lower_generics_mut (
870870 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 ) ,
875872 ) ;
876873 let res = f ( this, & mut params) ;
877874 ( params, ( generics, res) )
@@ -1077,7 +1074,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10771074 }
10781075 AssocTyConstraintKind :: Bound { ref bounds } => {
10791076 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 ;
10811078 // Piggy-back on the `impl Trait` context to figure out the correct behavior.
10821079 let ( desugar_to_impl_trait, itctx) = match itctx {
10831080 // We are in the return position:
@@ -1198,7 +1195,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11981195
11991196 // Construct a AnonConst where the expr is the "ty"'s path.
12001197
1201- let parent_def_id = self . current_hir_id_owner . last ( ) . unwrap ( ) . 0 ;
1198+ let parent_def_id = self . current_hir_id_owner . 0 ;
12021199 let node_id = self . resolver . next_node_id ( ) ;
12031200
12041201 // Add a definition for the in-band const def.
@@ -1814,10 +1811,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18141811 if let Some ( ( _, ibty) ) = & mut in_band_ty_params {
18151812 this. lower_ty_direct (
18161813 & 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 ) ,
18211815 )
18221816 } else {
18231817 this. lower_ty_direct ( & param. ty , ImplTraitContext :: disallowed ( ) )
0 commit comments