]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/simplify_try.rs
Rollup merge of #100382 - jackh726:gat-self-outlives-input, r=compiler-errors
[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`, but `try_trait_v2` uses a different structure,
17 // so the relevant desugar is copied inline in order to keep the test testing the same thing.
18 // FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR
19 // optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not.
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 }