Skip to content

Commit 0244355

Browse files
break out to one scope higher for let-else
1 parent c907b6f commit 0244355

File tree

1 file changed

+17
-2
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+17
-2
lines changed

Diff for: compiler/rustc_mir_build/src/build/block.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::build::matches::ArmHasGuard;
22
use crate::build::ForGuard::OutsideGuard;
33
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
4+
use rustc_middle::middle::region::Scope;
45
use rustc_middle::thir::*;
56
use rustc_middle::{mir::*, ty};
67
use 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

Comments
 (0)