@@ -2,17 +2,20 @@ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
22use crate :: build:: ForGuard :: OutsideGuard ;
33use crate :: build:: matches:: ArmHasGuard ;
44use crate :: hair:: * ;
5+ use rustc:: middle:: region;
56use rustc:: mir:: * ;
67use rustc:: hir;
78use syntax_pos:: Span ;
89
910impl < ' a , ' tcx > Builder < ' a , ' tcx > {
10- pub fn ast_block ( & mut self ,
11- destination : & Place < ' tcx > ,
12- block : BasicBlock ,
13- ast_block : & ' tcx hir:: Block ,
14- source_info : SourceInfo )
15- -> BlockAnd < ( ) > {
11+ pub fn ast_block (
12+ & mut self ,
13+ destination : & Place < ' tcx > ,
14+ scope : Option < region:: Scope > ,
15+ block : BasicBlock ,
16+ ast_block : & ' tcx hir:: Block ,
17+ source_info : SourceInfo ,
18+ ) -> BlockAnd < ( ) > {
1619 let Block {
1720 region_scope,
1821 opt_destruction_scope,
@@ -21,37 +24,50 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2124 expr,
2225 targeted_by_break,
2326 safety_mode
24- } =
25- self . hir . mirror ( ast_block) ;
27+ } = self . hir . mirror ( ast_block) ;
2628 self . in_opt_scope ( opt_destruction_scope. map ( |de|( de, source_info) ) , move |this| {
2729 this. in_scope ( ( region_scope, source_info) , LintLevel :: Inherited , move |this| {
2830 if targeted_by_break {
29- // This is a `break`-able block
30- let exit_block = this. cfg . start_new_block ( ) ;
31- let block_exit = this. in_breakable_scope (
32- None , exit_block, destination. clone ( ) , |this| {
33- this. ast_block_stmts ( destination, block, span, stmts, expr,
34- safety_mode)
35- } ) ;
36- this. cfg . terminate ( unpack ! ( block_exit) , source_info,
37- TerminatorKind :: Goto { target : exit_block } ) ;
38- exit_block. unit ( )
31+ this. in_breakable_scope (
32+ None ,
33+ destination. clone ( ) ,
34+ scope,
35+ span,
36+ |this| Some ( this. ast_block_stmts (
37+ destination,
38+ scope,
39+ block,
40+ span,
41+ stmts,
42+ expr,
43+ safety_mode,
44+ ) ) ,
45+ )
3946 } else {
40- this. ast_block_stmts ( destination, block, span, stmts, expr,
41- safety_mode)
47+ this. ast_block_stmts (
48+ destination,
49+ scope,
50+ block,
51+ span,
52+ stmts,
53+ expr,
54+ safety_mode,
55+ )
4256 }
4357 } )
4458 } )
4559 }
4660
47- fn ast_block_stmts ( & mut self ,
48- destination : & Place < ' tcx > ,
49- mut block : BasicBlock ,
50- span : Span ,
51- stmts : Vec < StmtRef < ' tcx > > ,
52- expr : Option < ExprRef < ' tcx > > ,
53- safety_mode : BlockSafety )
54- -> BlockAnd < ( ) > {
61+ fn ast_block_stmts (
62+ & mut self ,
63+ destination : & Place < ' tcx > ,
64+ scope : Option < region:: Scope > ,
65+ mut block : BasicBlock ,
66+ span : Span ,
67+ stmts : Vec < StmtRef < ' tcx > > ,
68+ expr : Option < ExprRef < ' tcx > > ,
69+ safety_mode : BlockSafety ,
70+ ) -> BlockAnd < ( ) > {
5571 let this = self ;
5672
5773 // This convoluted structure is to avoid using recursion as we walk down a list
@@ -177,7 +193,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
177193 this. block_context . currently_ignores_tail_results ( ) ;
178194 this. block_context . push ( BlockFrame :: TailExpr { tail_result_is_ignored } ) ;
179195
180- unpack ! ( block = this. into( destination, block, expr) ) ;
196+ unpack ! ( block = this. into( destination, scope , block, expr) ) ;
181197 let popped = this. block_context . pop ( ) ;
182198
183199 assert ! ( popped. map_or( false , |bf|bf. is_tail_expr( ) ) ) ;
0 commit comments