From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/mir-opt/simplify_try.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/mir-opt/simplify_try.rs (limited to 'src/test/mir-opt/simplify_try.rs') diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs new file mode 100644 index 000000000..15e351e7d --- /dev/null +++ b/src/test/mir-opt/simplify_try.rs @@ -0,0 +1,30 @@ +// compile-flags: -Zunsound-mir-opts +// EMIT_MIR simplify_try.try_identity.SimplifyArmIdentity.diff +// EMIT_MIR simplify_try.try_identity.SimplifyBranchSame.after.mir +// EMIT_MIR simplify_try.try_identity.SimplifyLocals.after.mir +// EMIT_MIR simplify_try.try_identity.DestinationPropagation.diff + + +fn into_result(r: Result) -> Result { + r +} + +fn from_error(e: E) -> Result { + 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 try_identity(x: Result) -> Result { + let y = match into_result(x) { + Err(e) => return from_error(From::from(e)), + Ok(v) => v, + }; + Ok(y) +} + +fn main() { + let _ = try_identity(Ok(0)); +} -- cgit v1.2.3