]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/mir/mir_match_test.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / mir / mir_match_test.rs
1 #![feature(exclusive_range_pattern)]
2
3 // run-pass
4
5 fn main() {
6 let incl_range = |x, b| {
7 match x {
8 0..=5 if b => 0,
9 5..=10 if b => 1,
10 1..=4 if !b => 2,
11 _ => 3,
12 }
13 };
14 assert_eq!(incl_range(3, false), 2);
15 assert_eq!(incl_range(3, true), 0);
16 assert_eq!(incl_range(5, false), 3);
17 assert_eq!(incl_range(5, true), 0);
18
19 let excl_range = |x, b| {
20 match x {
21 0..5 if b => 0,
22 5..10 if b => 1,
23 1..4 if !b => 2,
24 _ => 3,
25 }
26 };
27 assert_eq!(excl_range(3, false), 2);
28 assert_eq!(excl_range(3, true), 0);
29 assert_eq!(excl_range(5, false), 3);
30 assert_eq!(excl_range(5, true), 1);
31
32 let incl_range_vs_const = |x, b| {
33 match x {
34 0..=5 if b => 0,
35 7 => 1,
36 3 => 2,
37 _ => 3,
38 }
39 };
40 assert_eq!(incl_range_vs_const(5, false), 3);
41 assert_eq!(incl_range_vs_const(5, true), 0);
42 assert_eq!(incl_range_vs_const(3, false), 2);
43 assert_eq!(incl_range_vs_const(3, true), 0);
44 assert_eq!(incl_range_vs_const(7, false), 1);
45 assert_eq!(incl_range_vs_const(7, true), 1);
46
47 let excl_range_vs_const = |x, b| {
48 match x {
49 0..5 if b => 0,
50 7 => 1,
51 3 => 2,
52 _ => 3,
53 }
54 };
55 assert_eq!(excl_range_vs_const(5, false), 3);
56 assert_eq!(excl_range_vs_const(5, true), 3);
57 assert_eq!(excl_range_vs_const(3, false), 2);
58 assert_eq!(excl_range_vs_const(3, true), 0);
59 assert_eq!(excl_range_vs_const(7, false), 1);
60 assert_eq!(excl_range_vs_const(7, true), 1);
61
62 let const_vs_incl_range = |x, b| {
63 match x {
64 3 if b => 0,
65 5..=7 => 2,
66 1..=4 => 1,
67 _ => 3,
68 }
69 };
70 assert_eq!(const_vs_incl_range(3, false), 1);
71 assert_eq!(const_vs_incl_range(3, true), 0);
72
73 let const_vs_excl_range = |x, b| {
74 match x {
75 3 if b => 0,
76 5..7 => 2,
77 1..4 => 1,
78 _ => 3,
79 }
80 };
81 assert_eq!(const_vs_excl_range(3, false), 1);
82 assert_eq!(const_vs_excl_range(3, true), 0);
83 }