From 835405199af7230a0349803f90d3ebd80487f23b Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Sat, 22 May 2021 04:14:35 +0800 Subject: [PATCH] Refactor `match` + `if` --- .../rustc_mir/src/interpret/eval_context.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 0c7e3780646..8c61d4c0895 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -143,7 +143,7 @@ pub enum StackPopUnwind { NotAllowed, } -#[derive(Clone, Eq, PartialEq, Debug, HashStable)] // Miri debug-prints these +#[derive(Clone, Copy, Eq, PartialEq, Debug, HashStable)] // Miri debug-prints these pub enum StackPopCleanup { /// Jump to the next block in the caller, or cause UB if None (that's a function /// that may never return). Also store layout of return place so @@ -815,21 +815,18 @@ pub(super) fn pop_stack_frame(&mut self, unwinding: bool) -> InterpResult<'tcx> // Usually we want to clean up (deallocate locals), but in a few rare cases we don't. // In that case, we return early. We also avoid validation in that case, // because this is CTFE and the final value will be thoroughly validated anyway. - let (cleanup, next_block) = match frame.return_to_block { - StackPopCleanup::Goto { ret, unwind } => ( + let (cleanup, next_block) = match (frame.return_to_block, unwinding) { + (StackPopCleanup::Goto { ret, .. }, false) => (true, Some(ret)), + (StackPopCleanup::Goto { unwind, .. }, true) => ( true, - Some(if unwinding { - match unwind { - StackPopUnwind::Cleanup(unwind) => unwind, - StackPopUnwind::NotAllowed => { - throw_ub_format!("unwind past a frame that does not allow unwinding") - } + Some(match unwind { + StackPopUnwind::Cleanup(unwind) => unwind, + StackPopUnwind::NotAllowed => { + throw_ub_format!("unwind past a frame that does not allow unwinding") } - } else { - ret }), ), - StackPopCleanup::None { cleanup, .. } => (cleanup, None), + (StackPopCleanup::None { cleanup, .. }, _) => (cleanup, None), }; if !cleanup { -- 2.44.0