From ad7f109bfaa92f84bbcdbb5d376edfd8e66812fd Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 5 Sep 2021 18:50:55 +0100 Subject: 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. --- compiler/rustc_mir_build/src/build/expr/into.rs | 2 +- compiler/rustc_mir_build/src/build/matches/mod.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'compiler') 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, 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]; -- cgit 1.4.1-3-g733a5