]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/matches_reduce_branches.rs
Rollup merge of #107719 - WaffleLapkin:de-arena-allocates-you-UwU, r=cjgillot
[rust.git] / tests / mir-opt / matches_reduce_branches.rs
1 // unit-test: MatchBranchSimplification
2
3
4 // EMIT_MIR matches_reduce_branches.foo.MatchBranchSimplification.diff
5 // EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
6 // EMIT_MIR matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff
7
8 fn foo(bar: Option<()>) {
9     if matches!(bar, None) {
10         ()
11     }
12 }
13
14 fn bar(i: i32) -> (bool, bool, bool, bool) {
15     let a;
16     let b;
17     let c;
18     let d;
19
20     match i {
21         7 => {
22             a = false;
23             b = true;
24             c = false;
25             d = true;
26             ()
27         }
28         _ => {
29             a = true;
30             b = false;
31             c = false;
32             d = true;
33             ()
34         }
35     };
36
37     (a, b, c, d)
38 }
39
40 fn match_nested_if() -> bool {
41     let val = match () {
42         () if if if if true { true } else { false } { true } else { false } {
43             true
44         } else {
45             false
46         } =>
47         {
48             true
49         }
50         _ => false,
51     };
52     val
53 }
54
55 fn main() {
56     let _ = foo(None);
57     let _ = foo(Some(()));
58     let _ = bar(0);
59     let _ = match_nested_if();
60 }