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-arm.rs | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/mir-opt/simplify-arm.rs (limited to 'src/test/mir-opt/simplify-arm.rs') diff --git a/src/test/mir-opt/simplify-arm.rs b/src/test/mir-opt/simplify-arm.rs new file mode 100644 index 000000000..f7dcaa134 --- /dev/null +++ b/src/test/mir-opt/simplify-arm.rs @@ -0,0 +1,47 @@ +// 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 + +fn id(o: Option) -> Option { + match o { + Some(v) => Some(v), + None => None, + } +} + +fn id_result(r: Result) -> Result { + match r { + Ok(x) => Ok(x), + Err(y) => Err(y), + } +} + +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 id_try(r: Result) -> Result { + 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)); +} -- cgit v1.2.3