@@ -1156,7 +1156,7 @@ impl<'a> LoweringContext<'a> {
1156
1156
bounds. iter ( ) . map ( |bound| self . lower_ty_param_bound ( bound) ) . collect ( )
1157
1157
}
1158
1158
1159
- fn lower_block ( & mut self , b : & Block , break_to : Option < NodeId > ) -> P < hir:: Block > {
1159
+ fn lower_block ( & mut self , b : & Block , targeted_by_break : bool ) -> P < hir:: Block > {
1160
1160
let mut expr = None ;
1161
1161
1162
1162
let mut stmts = vec ! [ ] ;
@@ -1179,7 +1179,7 @@ impl<'a> LoweringContext<'a> {
1179
1179
expr : expr,
1180
1180
rules : self . lower_block_check_mode ( & b. rules ) ,
1181
1181
span : b. span ,
1182
- break_to_expr_id : break_to ,
1182
+ targeted_by_break : targeted_by_break ,
1183
1183
} )
1184
1184
}
1185
1185
@@ -1274,7 +1274,7 @@ impl<'a> LoweringContext<'a> {
1274
1274
}
1275
1275
ItemKind :: Fn ( ref decl, unsafety, constness, abi, ref generics, ref body) => {
1276
1276
self . with_new_scopes ( |this| {
1277
- let body = this. lower_block ( body, None ) ;
1277
+ let body = this. lower_block ( body, false ) ;
1278
1278
let body = this. expr_block ( body, ThinVec :: new ( ) ) ;
1279
1279
let body_id = this. record_body ( body, Some ( decl) ) ;
1280
1280
hir:: ItemFn ( this. lower_fn_decl ( decl) ,
@@ -1368,7 +1368,7 @@ impl<'a> LoweringContext<'a> {
1368
1368
hir:: TraitMethod :: Required ( names) )
1369
1369
}
1370
1370
TraitItemKind :: Method ( ref sig, Some ( ref body) ) => {
1371
- let body = this. lower_block ( body, None ) ;
1371
+ let body = this. lower_block ( body, false ) ;
1372
1372
let expr = this. expr_block ( body, ThinVec :: new ( ) ) ;
1373
1373
let body_id = this. record_body ( expr, Some ( & sig. decl ) ) ;
1374
1374
hir:: TraitItemKind :: Method ( this. lower_method_sig ( sig) ,
@@ -1424,7 +1424,7 @@ impl<'a> LoweringContext<'a> {
1424
1424
hir:: ImplItemKind :: Const ( this. lower_ty ( ty) , body_id)
1425
1425
}
1426
1426
ImplItemKind :: Method ( ref sig, ref body) => {
1427
- let body = this. lower_block ( body, None ) ;
1427
+ let body = this. lower_block ( body, false ) ;
1428
1428
let expr = this. expr_block ( body, ThinVec :: new ( ) ) ;
1429
1429
let body_id = this. record_body ( expr, Some ( & sig. decl ) ) ;
1430
1430
hir:: ImplItemKind :: Method ( this. lower_method_sig ( sig) , body_id)
@@ -1848,32 +1848,35 @@ impl<'a> LoweringContext<'a> {
1848
1848
id : id,
1849
1849
rules : hir:: DefaultBlock ,
1850
1850
span : span,
1851
- break_to_expr_id : None ,
1851
+ targeted_by_break : false ,
1852
1852
} ) ;
1853
1853
P ( self . expr_block ( blk, ThinVec :: new ( ) ) )
1854
1854
}
1855
1855
_ => P ( self . lower_expr ( els) ) ,
1856
1856
}
1857
1857
} ) ;
1858
1858
1859
- hir:: ExprIf ( P ( self . lower_expr ( cond) ) , self . lower_block ( blk, None ) , else_opt)
1859
+ let then_blk = self . lower_block ( blk, false ) ;
1860
+ let then_expr = self . expr_block ( then_blk, ThinVec :: new ( ) ) ;
1861
+
1862
+ hir:: ExprIf ( P ( self . lower_expr ( cond) ) , P ( then_expr) , else_opt)
1860
1863
}
1861
1864
ExprKind :: While ( ref cond, ref body, opt_ident) => {
1862
1865
self . with_loop_scope ( e. id , |this|
1863
1866
hir:: ExprWhile (
1864
1867
this. with_loop_condition_scope ( |this| P ( this. lower_expr ( cond) ) ) ,
1865
- this. lower_block ( body, None ) ,
1868
+ this. lower_block ( body, false ) ,
1866
1869
this. lower_opt_sp_ident ( opt_ident) ) )
1867
1870
}
1868
1871
ExprKind :: Loop ( ref body, opt_ident) => {
1869
1872
self . with_loop_scope ( e. id , |this|
1870
- hir:: ExprLoop ( this. lower_block ( body, None ) ,
1873
+ hir:: ExprLoop ( this. lower_block ( body, false ) ,
1871
1874
this. lower_opt_sp_ident ( opt_ident) ,
1872
1875
hir:: LoopSource :: Loop ) )
1873
1876
}
1874
1877
ExprKind :: Catch ( ref body) => {
1875
- self . with_catch_scope ( e . id , |this|
1876
- hir:: ExprBlock ( this. lower_block ( body, Some ( e . id ) ) ) )
1878
+ self . with_catch_scope ( body . id , |this|
1879
+ hir:: ExprBlock ( this. lower_block ( body, true ) ) )
1877
1880
}
1878
1881
ExprKind :: Match ( ref expr, ref arms) => {
1879
1882
hir:: ExprMatch ( P ( self . lower_expr ( expr) ) ,
@@ -1891,7 +1894,7 @@ impl<'a> LoweringContext<'a> {
1891
1894
} )
1892
1895
} )
1893
1896
}
1894
- ExprKind :: Block ( ref blk) => hir:: ExprBlock ( self . lower_block ( blk, None ) ) ,
1897
+ ExprKind :: Block ( ref blk) => hir:: ExprBlock ( self . lower_block ( blk, false ) ) ,
1895
1898
ExprKind :: Assign ( ref el, ref er) => {
1896
1899
hir:: ExprAssign ( P ( self . lower_expr ( el) ) , P ( self . lower_expr ( er) ) )
1897
1900
}
@@ -2037,7 +2040,7 @@ impl<'a> LoweringContext<'a> {
2037
2040
2038
2041
// `<pat> => <body>`
2039
2042
{
2040
- let body = self . lower_block ( body, None ) ;
2043
+ let body = self . lower_block ( body, false ) ;
2041
2044
let body_expr = P ( self . expr_block ( body, ThinVec :: new ( ) ) ) ;
2042
2045
let pat = self . lower_pat ( pat) ;
2043
2046
arms. push ( self . arm ( hir_vec ! [ pat] , body_expr) ) ;
@@ -2109,7 +2112,7 @@ impl<'a> LoweringContext<'a> {
2109
2112
let ( guard, body) = if let ExprKind :: If ( ref cond,
2110
2113
ref then,
2111
2114
_) = else_expr. node {
2112
- let then = self . lower_block ( then, None ) ;
2115
+ let then = self . lower_block ( then, false ) ;
2113
2116
( Some ( cond) ,
2114
2117
self . expr_block ( then, ThinVec :: new ( ) ) )
2115
2118
} else {
@@ -2159,7 +2162,7 @@ impl<'a> LoweringContext<'a> {
2159
2162
// Note that the block AND the condition are evaluated in the loop scope.
2160
2163
// This is done to allow `break` from inside the condition of the loop.
2161
2164
let ( body, break_expr, sub_expr) = self . with_loop_scope ( e. id , |this| (
2162
- this. lower_block ( body, None ) ,
2165
+ this. lower_block ( body, false ) ,
2163
2166
this. expr_break ( e. span , ThinVec :: new ( ) ) ,
2164
2167
this. with_loop_condition_scope ( |this| P ( this. lower_expr ( sub_expr) ) ) ,
2165
2168
) ) ;
@@ -2220,7 +2223,7 @@ impl<'a> LoweringContext<'a> {
2220
2223
// `::std::option::Option::Some(<pat>) => <body>`
2221
2224
let pat_arm = {
2222
2225
let body_block = self . with_loop_scope ( e. id ,
2223
- |this| this. lower_block ( body, None ) ) ;
2226
+ |this| this. lower_block ( body, false ) ) ;
2224
2227
let body_expr = P ( self . expr_block ( body_block, ThinVec :: new ( ) ) ) ;
2225
2228
let pat = self . lower_pat ( pat) ;
2226
2229
let some_pat = self . pat_some ( e. span , pat) ;
@@ -2652,7 +2655,7 @@ impl<'a> LoweringContext<'a> {
2652
2655
id : self . next_id ( ) ,
2653
2656
rules : hir:: DefaultBlock ,
2654
2657
span : span,
2655
- break_to_expr_id : None ,
2658
+ targeted_by_break : false ,
2656
2659
}
2657
2660
}
2658
2661
@@ -2760,7 +2763,7 @@ impl<'a> LoweringContext<'a> {
2760
2763
id : id,
2761
2764
stmts : stmts,
2762
2765
expr : Some ( expr) ,
2763
- break_to_expr_id : None ,
2766
+ targeted_by_break : false ,
2764
2767
} ) ;
2765
2768
self . expr_block ( block, attrs)
2766
2769
}
0 commit comments