From 8ea5ac60b6723356dc14954d10c5069175f61fc2 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 3 Mar 2020 12:05:59 -0800 Subject: [PATCH 1/2] Add `mir-opt` test for better drop elaboration --- .../mir-opt/no-drop-for-inactive-variant.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/mir-opt/no-drop-for-inactive-variant.rs diff --git a/src/test/mir-opt/no-drop-for-inactive-variant.rs b/src/test/mir-opt/no-drop-for-inactive-variant.rs new file mode 100644 index 0000000000000..cccfa2e1d41af --- /dev/null +++ b/src/test/mir-opt/no-drop-for-inactive-variant.rs @@ -0,0 +1,41 @@ +// Ensure that there are no drop terminators in `unwrap` (except the one along the cleanup +// path). + +fn unwrap(opt: Option) -> T { + match opt { + Some(x) => x, + None => panic!(), + } +} + +fn main() { + let _ = unwrap(Some(1i32)); +} + +// END RUST SOURCE +// START rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir +// fn unwrap(_1: std::option::Option) -> T { +// ... +// bb0: { +// ... +// switchInt(move _2) -> [0isize: bb2, 1isize: bb4, otherwise: bb3]; +// } +// bb1 (cleanup): { +// resume; +// } +// bb2: { +// ... +// const std::rt::begin_panic::<&'static str>(const "explicit panic") -> bb5; +// } +// bb3: { +// unreachable; +// } +// bb4: { +// ... +// return; +// } +// bb5 (cleanup): { +// drop(_1) -> bb1; +// } +// } +// END rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir From 68f20019f717db44e0c07d80af10878a517255a3 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 5 Mar 2020 11:52:50 -0800 Subject: [PATCH 2/2] Ignore `mir-opt` test when panic=abort --- src/test/mir-opt/no-drop-for-inactive-variant.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/mir-opt/no-drop-for-inactive-variant.rs b/src/test/mir-opt/no-drop-for-inactive-variant.rs index cccfa2e1d41af..f906761684526 100644 --- a/src/test/mir-opt/no-drop-for-inactive-variant.rs +++ b/src/test/mir-opt/no-drop-for-inactive-variant.rs @@ -1,3 +1,5 @@ +// ignore-wasm32-bare compiled with panic=abort by default + // Ensure that there are no drop terminators in `unwrap` (except the one along the cleanup // path).