@@ -2,17 +2,20 @@ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
2
2
use crate :: build:: ForGuard :: OutsideGuard ;
3
3
use crate :: build:: matches:: ArmHasGuard ;
4
4
use crate :: hair:: * ;
5
+ use rustc:: middle:: region;
5
6
use rustc:: mir:: * ;
6
7
use rustc:: hir;
7
8
use syntax_pos:: Span ;
8
9
9
10
impl < ' 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 < ( ) > {
16
19
let Block {
17
20
region_scope,
18
21
opt_destruction_scope,
@@ -21,37 +24,50 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21
24
expr,
22
25
targeted_by_break,
23
26
safety_mode
24
- } =
25
- self . hir . mirror ( ast_block) ;
27
+ } = self . hir . mirror ( ast_block) ;
26
28
self . in_opt_scope ( opt_destruction_scope. map ( |de|( de, source_info) ) , move |this| {
27
29
this. in_scope ( ( region_scope, source_info) , LintLevel :: Inherited , move |this| {
28
30
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
+ )
39
46
} 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
+ )
42
56
}
43
57
} )
44
58
} )
45
59
}
46
60
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 < ( ) > {
55
71
let this = self ;
56
72
57
73
// This convoluted structure is to avoid using recursion as we walk down a list
@@ -177,7 +193,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
177
193
this. block_context . currently_ignores_tail_results ( ) ;
178
194
this. block_context . push ( BlockFrame :: TailExpr { tail_result_is_ignored } ) ;
179
195
180
- unpack ! ( block = this. into( destination, block, expr) ) ;
196
+ unpack ! ( block = this. into( destination, scope , block, expr) ) ;
181
197
let popped = this. block_context . pop ( ) ;
182
198
183
199
assert ! ( popped. map_or( false , |bf|bf. is_tail_expr( ) ) ) ;
0 commit comments