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