]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/simplify_arm.rs
Rollup merge of #107108 - sulami:issue-83968-doc-alias-typo-suggestions, r=compiler...
[rust.git] / tests / mir-opt / simplify_arm.rs
1 // compile-flags: -Z mir-opt-level=3 -Zunsound-mir-opts
2 // EMIT_MIR simplify_arm.id.SimplifyArmIdentity.diff
3 // EMIT_MIR simplify_arm.id.SimplifyBranchSame.diff
4 // EMIT_MIR simplify_arm.id_result.SimplifyArmIdentity.diff
5 // EMIT_MIR simplify_arm.id_result.SimplifyBranchSame.diff
6 // EMIT_MIR simplify_arm.id_try.SimplifyArmIdentity.diff
7 // EMIT_MIR simplify_arm.id_try.SimplifyBranchSame.diff
8
9 // This pass is broken since deaggregation changed
10 // ignore-test
11
12 fn id(o: Option<u8>) -> Option<u8> {
13     match o {
14         Some(v) => Some(v),
15         None => None,
16     }
17 }
18
19 fn id_result(r: Result<u8, i32>) -> Result<u8, i32> {
20     match r {
21         Ok(x) => Ok(x),
22         Err(y) => Err(y),
23     }
24 }
25
26 fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
27     r
28 }
29
30 fn from_error<T, E>(e: E) -> Result<T, E> {
31     Err(e)
32 }
33
34 // This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure,
35 // so the relevant desugar is copied inline in order to keep the test testing the same thing.
36 // FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR
37 // optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not.
38 fn id_try(r: Result<u8, i32>) -> Result<u8, i32> {
39     let x = match into_result(r) {
40         Err(e) => return from_error(From::from(e)),
41         Ok(v) => v,
42     };
43     Ok(x)
44 }
45
46 fn main() {
47     id(None);
48     id_result(Ok(4));
49     id_try(Ok(4));
50 }