@@ -21,21 +21,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
21
21
ast_block : & ' tcx hir:: Block ,
22
22
source_info : SourceInfo )
23
23
-> BlockAnd < ( ) > {
24
- let Block { extent, span, stmts, expr, targeted_by_break } = self . hir . mirror ( ast_block) ;
25
- self . in_scope ( extent, block, move |this| {
26
- if targeted_by_break {
27
- // This is a `break`-able block (currently only `catch { ... }`)
28
- let exit_block = this. cfg . start_new_block ( ) ;
29
- let block_exit = this. in_breakable_scope ( None , exit_block,
30
- destination. clone ( ) , |this| {
24
+ let Block { extent, opt_destruction_extent, span, stmts, expr, targeted_by_break } =
25
+ self . hir . mirror ( ast_block) ;
26
+ self . in_opt_scope ( opt_destruction_extent. map ( |de|( de, source_info) ) , block, move |this| {
27
+ this. in_scope ( ( extent, source_info) , block, move |this| {
28
+ if targeted_by_break {
29
+ // This is a `break`-able block (currently only `catch { ... }`)
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
+ } ) ;
35
+ this. cfg . terminate ( unpack ! ( block_exit) , source_info,
36
+ TerminatorKind :: Goto { target : exit_block } ) ;
37
+ exit_block. unit ( )
38
+ } else {
31
39
this. ast_block_stmts ( destination, block, span, stmts, expr)
32
- } ) ;
33
- this. cfg . terminate ( unpack ! ( block_exit) , source_info,
34
- TerminatorKind :: Goto { target : exit_block } ) ;
35
- exit_block. unit ( )
36
- } else {
37
- this. ast_block_stmts ( destination, block, span, stmts, expr)
38
- }
40
+ }
41
+ } )
39
42
} )
40
43
}
41
44
@@ -66,14 +69,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
66
69
// First we build all the statements in the block.
67
70
let mut let_extent_stack = Vec :: with_capacity ( 8 ) ;
68
71
let outer_visibility_scope = this. visibility_scope ;
72
+ let source_info = this. source_info ( span) ;
69
73
for stmt in stmts {
70
- let Stmt { span : _ , kind } = this. hir . mirror ( stmt) ;
74
+ let Stmt { span, kind, opt_destruction_extent } = this. hir . mirror ( stmt) ;
71
75
match kind {
72
76
StmtKind :: Expr { scope, expr } => {
73
- unpack ! ( block = this. in_scope( scope, block, |this| {
74
- let expr = this. hir. mirror( expr) ;
75
- this. stmt_expr( block, expr)
76
- } ) ) ;
77
+ unpack ! ( block = this. in_opt_scope(
78
+ opt_destruction_extent. map( |de|( de, source_info) ) , block, |this| {
79
+ this. in_scope( ( scope, source_info) , block, |this| {
80
+ let expr = this. hir. mirror( expr) ;
81
+ this. stmt_expr( block, expr)
82
+ } )
83
+ } ) ) ;
77
84
}
78
85
StmtKind :: Let { remainder_scope, init_scope, pattern, initializer } => {
79
86
let tcx = this. hir . tcx ( ) ;
@@ -89,10 +96,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
89
96
90
97
// Evaluate the initializer, if present.
91
98
if let Some ( init) = initializer {
92
- unpack ! ( block = this. in_scope( init_scope, block, move |this| {
93
- // FIXME #30046 ^~~~
94
- this. expr_into_pattern( block, pattern, init)
95
- } ) ) ;
99
+ unpack ! ( block = this. in_opt_scope(
100
+ opt_destruction_extent. map( |de|( de, source_info) ) , block, move |this| {
101
+ this. in_scope( ( init_scope, source_info) , block, move |this| {
102
+ // FIXME #30046 ^~~~
103
+ this. expr_into_pattern( block, pattern, init)
104
+ } )
105
+ } ) ) ;
96
106
} else {
97
107
this. visit_bindings ( & pattern, & mut |this, _, _, node, span, _| {
98
108
this. storage_live_binding ( block, node, span) ;
@@ -112,13 +122,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
112
122
if let Some ( expr) = expr {
113
123
unpack ! ( block = this. into( destination, block, expr) ) ;
114
124
} else {
115
- let source_info = this. source_info ( span) ;
116
125
this. cfg . push_assign_unit ( block, source_info, destination) ;
117
126
}
118
127
// Finally, we pop all the let scopes before exiting out from the scope of block
119
128
// itself.
120
129
for extent in let_extent_stack. into_iter ( ) . rev ( ) {
121
- unpack ! ( block = this. pop_scope( extent, block) ) ;
130
+ unpack ! ( block = this. pop_scope( ( extent, source_info ) , block) ) ;
122
131
}
123
132
// Restore the original visibility scope.
124
133
this. visibility_scope = outer_visibility_scope;
0 commit comments