11use crate :: build:: matches:: ArmHasGuard ;
22use crate :: build:: ForGuard :: OutsideGuard ;
33use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
4+ use rustc_middle:: middle:: region:: Scope ;
45use rustc_middle:: thir:: * ;
56use rustc_middle:: { mir:: * , ty} ;
67use rustc_span:: Span ;
@@ -34,10 +35,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3435 & stmts,
3536 expr,
3637 safety_mode,
38+ region_scope,
3739 ) )
3840 } )
3941 } 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+ )
4151 }
4252 } )
4353 } )
@@ -51,6 +61,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5161 stmts : & [ StmtId ] ,
5262 expr : Option < & Expr < ' tcx > > ,
5363 safety_mode : BlockSafety ,
64+ region_scope : Scope ,
5465 ) -> BlockAnd < ( ) > {
5566 let this = self ;
5667
@@ -73,6 +84,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7384 let mut let_scope_stack = Vec :: with_capacity ( 8 ) ;
7485 let outer_source_scope = this. source_scope ;
7586 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;
7690 this. update_source_scope_for_safety_mode ( span, safety_mode) ;
7791
7892 let source_info = this. source_info ( span) ;
@@ -132,7 +146,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
132146 initializer_span,
133147 else_block,
134148 visibility_scope,
135- * remainder_scope ,
149+ last_remainder_scope ,
136150 remainder_span,
137151 pattern,
138152 )
@@ -178,6 +192,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178192 if let Some ( source_scope) = visibility_scope {
179193 this. source_scope = source_scope;
180194 }
195+ last_remainder_scope = * remainder_scope;
181196 }
182197 }
183198
0 commit comments