about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2021-09-05 18:50:55 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2021-09-05 18:50:55 +0100
commitad7f109bfaa92f84bbcdbb5d376edfd8e66812fd (patch)
treeb686b8a93653fdb039610e2e20bac2b9b6e9ac1a /compiler/rustc_mir_build/src
parent226e181b80fa0be755872b66916ef7e704601ec2 (diff)
downloadrust-ad7f109bfaa92f84bbcdbb5d376edfd8e66812fd.tar.gz
rust-ad7f109bfaa92f84bbcdbb5d376edfd8e66812fd.zip
Change scope of temporaries in match guards
Each pattern in a match arm has its own copy of the match guard in MIR,
with its own temporary, so it has to be dropped before the the guards
are joined to the single copy of the arm.
Diffstat (limited to 'compiler/rustc_mir_build/src')
-rw-r--r--compiler/rustc_mir_build/src/build/expr/into.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/matches/mod.rs8
2 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs
index 22c44beb350..e30e758e637 100644
--- a/compiler/rustc_mir_build/src/build/expr/into.rs
+++ b/compiler/rustc_mir_build/src/build/expr/into.rs
@@ -68,7 +68,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                                     let then_blk = unpack!(this.then_else_break(
                                         block,
                                         &this.thir[cond],
-                                        condition_scope,
+                                        Some(condition_scope),
                                         condition_scope,
                                         then_expr.span,
                                     ));
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs
index ec54a2a0ec4..ba94e15444a 100644
--- a/compiler/rustc_mir_build/src/build/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/build/matches/mod.rs
@@ -39,7 +39,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         &mut self,
         mut block: BasicBlock,
         expr: &Expr<'tcx>,
-        temp_scope: region::Scope,
+        temp_scope_override: Option<region::Scope>,
         break_scope: region::Scope,
         variable_scope_span: Span,
     ) -> BlockAnd<()> {
@@ -53,7 +53,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     this.then_else_break(
                         block,
                         &this.thir[value],
-                        temp_scope,
+                        temp_scope_override,
                         break_scope,
                         variable_scope_span,
                     )
@@ -63,6 +63,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 this.lower_let_expr(block, &this.thir[expr], pat, break_scope, variable_scope_span)
             }
             _ => {
+                let temp_scope = temp_scope_override.unwrap_or_else(|| this.local_scope());
                 let mutability = Mutability::Mut;
                 let place =
                     unpack!(block = this.as_temp(block, Some(temp_scope), expr, mutability));
@@ -1948,7 +1949,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             }
 
             let arm_span = arm_span.unwrap();
-            let arm_scope = self.local_scope();
             let match_scope = match_scope.unwrap();
             let mut guard_span = rustc_span::DUMMY_SP;
 
@@ -1957,7 +1957,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     Guard::If(e) => {
                         let e = &this.thir[e];
                         guard_span = e.span;
-                        this.then_else_break(block, e, arm_scope, match_scope, arm_span)
+                        this.then_else_break(block, e, None, match_scope, arm_span)
                     }
                     Guard::IfLet(ref pat, scrutinee) => {
                         let s = &this.thir[scrutinee];