From b98d6228dbf818ba68c9d99ccd77b0204e9735e8 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Sat, 22 May 2021 21:05:59 +0800 Subject: [PATCH] `Cleanup(Option<_>)` -> `Cleanup(BasicBlock), Skip` --- compiler/rustc_mir/src/interpret/eval_context.rs | 7 +++++-- compiler/rustc_mir/src/interpret/terminator.rs | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 8c61d4c0895d..b683aca9f057 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -138,7 +138,9 @@ pub struct FrameInfo<'tcx> { #[derive(Clone, Copy, Eq, PartialEq, Debug, HashStable)] pub enum StackPopUnwind { /// The cleanup block. - Cleanup(Option), + Cleanup(mir::BasicBlock), + /// No cleanup needs to be done. + Skip, /// Unwinding is not allowed (UB). NotAllowed, } @@ -820,7 +822,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { (StackPopCleanup::Goto { unwind, .. }, true) => ( true, Some(match unwind { - StackPopUnwind::Cleanup(unwind) => unwind, + StackPopUnwind::Cleanup(unwind) => Some(unwind), + StackPopUnwind::Skip => None, StackPopUnwind::NotAllowed => { throw_ub_format!("unwind past a frame that does not allow unwinding") } diff --git a/compiler/rustc_mir/src/interpret/terminator.rs b/compiler/rustc_mir/src/interpret/terminator.rs index 2564ea95e438..27b2716c5bd6 100644 --- a/compiler/rustc_mir/src/interpret/terminator.rs +++ b/compiler/rustc_mir/src/interpret/terminator.rs @@ -316,10 +316,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ret.map(|p| p.0), StackPopCleanup::Goto { ret: ret.map(|p| p.1), - unwind: if can_unwind { - StackPopUnwind::Cleanup(unwind) - } else { - StackPopUnwind::NotAllowed + unwind: match (unwind, can_unwind) { + (Some(unwind), true) => StackPopUnwind::Cleanup(unwind), + (None, true) => StackPopUnwind::Skip, + (_, false) => StackPopUnwind::NotAllowed, }, }, )?;