about summary refs log tree commit diff
path: root/tests/mir-opt/simplify_arm.rs
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/mir-opt/simplify_arm.rs
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/mir-opt/simplify_arm.rs')
-rw-r--r--tests/mir-opt/simplify_arm.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/mir-opt/simplify_arm.rs b/tests/mir-opt/simplify_arm.rs
new file mode 100644
index 00000000000..c247872e2af
--- /dev/null
+++ b/tests/mir-opt/simplify_arm.rs
@@ -0,0 +1,50 @@
+// compile-flags: -Z mir-opt-level=3 -Zunsound-mir-opts
+// EMIT_MIR simplify_arm.id.SimplifyArmIdentity.diff
+// EMIT_MIR simplify_arm.id.SimplifyBranchSame.diff
+// EMIT_MIR simplify_arm.id_result.SimplifyArmIdentity.diff
+// EMIT_MIR simplify_arm.id_result.SimplifyBranchSame.diff
+// EMIT_MIR simplify_arm.id_try.SimplifyArmIdentity.diff
+// EMIT_MIR simplify_arm.id_try.SimplifyBranchSame.diff
+
+// This pass is broken since deaggregation changed
+// ignore-test
+
+fn id(o: Option<u8>) -> Option<u8> {
+    match o {
+        Some(v) => Some(v),
+        None => None,
+    }
+}
+
+fn id_result(r: Result<u8, i32>) -> Result<u8, i32> {
+    match r {
+        Ok(x) => Ok(x),
+        Err(y) => Err(y),
+    }
+}
+
+fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
+    r
+}
+
+fn from_error<T, E>(e: E) -> Result<T, E> {
+    Err(e)
+}
+
+// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure,
+// so the relevant desugar is copied inline in order to keep the test testing the same thing.
+// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR
+// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not.
+fn id_try(r: Result<u8, i32>) -> Result<u8, i32> {
+    let x = match into_result(r) {
+        Err(e) => return from_error(From::from(e)),
+        Ok(v) => v,
+    };
+    Ok(x)
+}
+
+fn main() {
+    id(None);
+    id_result(Ok(4));
+    id_try(Ok(4));
+}