diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
commit | a4b7ed7a42c716ab9f05e351f003d589124fd55d (patch) | |
tree | b620cd3f223850b28716e474e80c58059dca5dd4 /tests/codegen/try_identity.rs | |
parent | Adding upstream version 1.67.1+dfsg1. (diff) | |
download | rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip |
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/try_identity.rs')
-rw-r--r-- | tests/codegen/try_identity.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/codegen/try_identity.rs b/tests/codegen/try_identity.rs new file mode 100644 index 000000000..92be90014 --- /dev/null +++ b/tests/codegen/try_identity.rs @@ -0,0 +1,34 @@ +// compile-flags: -C no-prepopulate-passes -O -Z mir-opt-level=3 -Zunsound-mir-opts + +// Ensure that `x?` has no overhead on `Result<T, E>` due to identity `match`es in lowering. +// This requires inlining to trigger the MIR optimizations in `SimplifyArmIdentity`. + +#![crate_type = "lib"] + +type R = Result<u64, i32>; + +// 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. +#[no_mangle] +pub fn try_identity(x: R) -> R { +// CHECK: start: +// FIXME(JakobDegen): Broken by deaggregation change CHECK-NOT\: br {{.*}} +// CHECK ret void + let y = match into_result(x) { + Err(e) => return from_error(From::from(e)), + Ok(v) => v, + }; + Ok(y) +} + +#[inline] +fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> { + r +} + +#[inline] +fn from_error<T, E>(e: E) -> Result<T, E> { + Err(e) +} |