]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/simplify_try.rs
a95cb665a97f371f54cd023c087e6526178ef43a
[rust.git] / src / test / mir-opt / simplify_try.rs
1 // compile-flags: -Zunsound-mir-opts
2 // EMIT_MIR simplify_try.try_identity.SimplifyArmIdentity.diff
3 // EMIT_MIR simplify_try.try_identity.SimplifyBranchSame.after.mir
4 // EMIT_MIR simplify_try.try_identity.SimplifyLocals.after.mir
5 // EMIT_MIR simplify_try.try_identity.DestinationPropagation.diff
6
7
8 fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
9     r
10 }
11
12 fn from_error<T, E>(e: E) -> Result<T, E> {
13     Err(e)
14 }
15
16 // This was written to the `?` from `try_trait`,
17 // but `try_trait_v2` uses a different structure,
18 // so the relevant desugar is copied inline
19 // in order to keep the test testing the same thing.
20 fn try_identity(x: Result<u32, i32>) -> Result<u32, i32> {
21     let y = match into_result(x) {
22         Err(e) => return from_error(From::from(e)),
23         Ok(v) => v,
24     };
25     Ok(y)
26 }
27
28 fn main() {
29     let _ = try_identity(Ok(0));
30 }