1
1
use crate :: build:: matches:: ArmHasGuard ;
2
2
use crate :: build:: ForGuard :: OutsideGuard ;
3
3
use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
4
+ use rustc_middle:: middle:: region:: Scope ;
4
5
use rustc_middle:: thir:: * ;
5
6
use rustc_middle:: { mir:: * , ty} ;
6
7
use rustc_span:: Span ;
@@ -34,10 +35,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
34
35
& stmts,
35
36
expr,
36
37
safety_mode,
38
+ region_scope,
37
39
) )
38
40
} )
39
41
} else {
40
- this. ast_block_stmts ( destination, block, span, & stmts, expr, safety_mode)
42
+ this. ast_block_stmts (
43
+ destination,
44
+ block,
45
+ span,
46
+ & stmts,
47
+ expr,
48
+ safety_mode,
49
+ region_scope,
50
+ )
41
51
}
42
52
} )
43
53
} )
@@ -51,6 +61,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
51
61
stmts : & [ StmtId ] ,
52
62
expr : Option < & Expr < ' tcx > > ,
53
63
safety_mode : BlockSafety ,
64
+ region_scope : Scope ,
54
65
) -> BlockAnd < ( ) > {
55
66
let this = self ;
56
67
@@ -73,6 +84,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
73
84
let mut let_scope_stack = Vec :: with_capacity ( 8 ) ;
74
85
let outer_source_scope = this. source_scope ;
75
86
let outer_in_scope_unsafe = this. in_scope_unsafe ;
87
+ // This scope information is kept for breaking out of the current block in case
88
+ // one let-else pattern matching fails.
89
+ let mut last_remainder_scope = region_scope;
76
90
this. update_source_scope_for_safety_mode ( span, safety_mode) ;
77
91
78
92
let source_info = this. source_info ( span) ;
@@ -132,7 +146,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
132
146
initializer_span,
133
147
else_block,
134
148
visibility_scope,
135
- * remainder_scope ,
149
+ last_remainder_scope ,
136
150
remainder_span,
137
151
pattern,
138
152
)
@@ -178,6 +192,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178
192
if let Some ( source_scope) = visibility_scope {
179
193
this. source_scope = source_scope;
180
194
}
195
+ last_remainder_scope = * remainder_scope;
181
196
}
182
197
}
183
198
0 commit comments