]> git.proxmox.com Git - rustc.git/blame - src/test/mir-opt/matches_reduce_branches.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / mir-opt / matches_reduce_branches.rs
CommitLineData
f2b60f7d
FG
1// unit-test: MatchBranchSimplification
2
3
3dfed10e
XL
4// EMIT_MIR matches_reduce_branches.foo.MatchBranchSimplification.diff
5// EMIT_MIR matches_reduce_branches.bar.MatchBranchSimplification.diff
29967ef6 6// EMIT_MIR matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff
3dfed10e
XL
7
8fn foo(bar: Option<()>) {
9 if matches!(bar, None) {
6a06907d 10 ()
3dfed10e
XL
11 }
12}
13
14fn 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
29967ef6
XL
40fn match_nested_if() -> bool {
41 let val = match () {
6a06907d
XL
42 () if if if if true { true } else { false } { true } else { false } {
43 true
44 } else {
45 false
46 } =>
47 {
48 true
49 }
29967ef6
XL
50 _ => false,
51 };
52 val
53}
3dfed10e
XL
54
55fn main() {
6a06907d
XL
56 let _ = foo(None);
57 let _ = foo(Some(()));
58 let _ = bar(0);
59 let _ = match_nested_if();
3dfed10e 60}