diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /src/test/mir-opt/simplify_arm.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/mir-opt/simplify_arm.rs')
-rw-r--r-- | src/test/mir-opt/simplify_arm.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/mir-opt/simplify_arm.rs b/src/test/mir-opt/simplify_arm.rs new file mode 100644 index 000000000..c247872e2 --- /dev/null +++ b/src/test/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)); +} |