about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-03-14 08:26:54 +0000
committerbors <bors@rust-lang.org>2020-03-14 08:26:54 +0000
commit42ce9b4e9054d63c8f352f994e2d5dae7d04130f (patch)
tree247c35fa458fab22b864f7ad9fd1e329a3dc9001 /src
parent5ed3453af9db9c516e564e25ba9ee28056d48103 (diff)
parent68f20019f717db44e0c07d80af10878a517255a3 (diff)
downloadrust-42ce9b4e9054d63c8f352f994e2d5dae7d04130f.tar.gz
rust-42ce9b4e9054d63c8f352f994e2d5dae7d04130f.zip
Auto merge of #69744 - ecstatic-morse:fix-enum-discr-effect-test, r=oli-obk
Add `mir-opt` test for more precise drop elaboration

Depends on #69676. This test should ensure that the problem fixed in that PR does not reoccur.

This has been split out from #69676 since the test fails on certain targets where no cleanup blocks are emitted. I have to find the correct `ignore` directives.

r? @oli-obk
Diffstat (limited to 'src')
-rw-r--r--src/test/mir-opt/no-drop-for-inactive-variant.rs43
1 files changed, 43 insertions, 0 deletions
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 00000000000..f9067616845
--- /dev/null
+++ b/src/test/mir-opt/no-drop-for-inactive-variant.rs
@@ -0,0 +1,43 @@
+// ignore-wasm32-bare compiled with panic=abort by default
+
+// Ensure that there are no drop terminators in `unwrap<T>` (except the one along the cleanup
+// path).
+
+fn unwrap<T>(opt: Option<T>) -> 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>) -> 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