@@ -1186,9 +1186,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1186
1186
}
1187
1187
}
1188
1188
None => self
1189
- . loop_scopes
1190
- . last ( )
1191
- . cloned ( )
1189
+ . loop_scope
1192
1190
. map ( |id| Ok ( self . lower_node_id ( id) ) )
1193
1191
. unwrap_or ( Err ( hir:: LoopIdError :: OutsideLoopScope ) ) ,
1194
1192
} ;
@@ -1208,18 +1206,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1208
1206
}
1209
1207
1210
1208
fn with_catch_scope < T > ( & mut self , catch_id : NodeId , f : impl FnOnce ( & mut Self ) -> T ) -> T {
1211
- let len = self . catch_scopes . len ( ) ;
1212
- self . catch_scopes . push ( catch_id) ;
1213
-
1209
+ let old_scope = self . catch_scope . replace ( catch_id) ;
1214
1210
let result = f ( self ) ;
1215
- assert_eq ! (
1216
- len + 1 ,
1217
- self . catch_scopes. len( ) ,
1218
- "catch scopes should be added and removed in stack order"
1219
- ) ;
1220
-
1221
- self . catch_scopes . pop ( ) . unwrap ( ) ;
1222
-
1211
+ self . catch_scope = old_scope;
1223
1212
result
1224
1213
}
1225
1214
@@ -1228,17 +1217,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1228
1217
let was_in_loop_condition = self . is_in_loop_condition ;
1229
1218
self . is_in_loop_condition = false ;
1230
1219
1231
- let len = self . loop_scopes . len ( ) ;
1232
- self . loop_scopes . push ( loop_id) ;
1233
-
1220
+ let old_scope = self . loop_scope . replace ( loop_id) ;
1234
1221
let result = f ( self ) ;
1235
- assert_eq ! (
1236
- len + 1 ,
1237
- self . loop_scopes. len( ) ,
1238
- "loop scopes should be added and removed in stack order"
1239
- ) ;
1240
-
1241
- self . loop_scopes . pop ( ) . unwrap ( ) ;
1222
+ self . loop_scope = old_scope;
1242
1223
1243
1224
self . is_in_loop_condition = was_in_loop_condition;
1244
1225
@@ -1565,8 +1546,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1565
1546
unstable_span,
1566
1547
) ;
1567
1548
let thin_attrs = ThinVec :: from ( attrs) ;
1568
- let catch_scope = self . catch_scopes . last ( ) . copied ( ) ;
1569
- let ret_expr = if let Some ( catch_node) = catch_scope {
1549
+ let ret_expr = if let Some ( catch_node) = self . catch_scope {
1570
1550
let target_id = Ok ( self . lower_node_id ( catch_node) ) ;
1571
1551
self . arena . alloc ( self . expr (
1572
1552
try_span,
0 commit comments