]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/usefulness/integer-ranges/reachability.rs
Rollup merge of #79293 - Havvy:test-eval-order-compound-assign, r=Mark-Simulacrum
[rust.git] / src / test / ui / pattern / usefulness / integer-ranges / reachability.rs
1 #![feature(exclusive_range_pattern)]
2 #![deny(unreachable_patterns)]
3
4 macro_rules! m {
5     ($s:expr, $t1:pat, $t2:pat) => {
6         match $s {
7             $t1 => {}
8             $t2 => {}
9             _ => {}
10         }
11     }
12 }
13
14 fn main() {
15     m!(0u8, 42, 41);
16     m!(0u8, 42, 42); //~ ERROR unreachable pattern
17     m!(0u8, 42, 43);
18
19     m!(0u8, 20..=30, 19);
20     m!(0u8, 20..=30, 20); //~ ERROR unreachable pattern
21     m!(0u8, 20..=30, 21); //~ ERROR unreachable pattern
22     m!(0u8, 20..=30, 25); //~ ERROR unreachable pattern
23     m!(0u8, 20..=30, 29); //~ ERROR unreachable pattern
24     m!(0u8, 20..=30, 30); //~ ERROR unreachable pattern
25     m!(0u8, 20..=30, 31);
26     m!(0u8, 20..30, 19);
27     m!(0u8, 20..30, 20); //~ ERROR unreachable pattern
28     m!(0u8, 20..30, 21); //~ ERROR unreachable pattern
29     m!(0u8, 20..30, 25); //~ ERROR unreachable pattern
30     m!(0u8, 20..30, 29); //~ ERROR unreachable pattern
31     m!(0u8, 20..30, 30);
32     m!(0u8, 20..30, 31);
33
34     m!(0u8, 20..=30, 20..=30); //~ ERROR unreachable pattern
35     m!(0u8, 20.. 30, 20.. 30); //~ ERROR unreachable pattern
36     m!(0u8, 20..=30, 20.. 30); //~ ERROR unreachable pattern
37     m!(0u8, 20..=30, 19..=30);
38     m!(0u8, 20..=30, 21..=30); //~ ERROR unreachable pattern
39     m!(0u8, 20..=30, 20..=29); //~ ERROR unreachable pattern
40     m!(0u8, 20..=30, 20..=31);
41     m!('a', 'A'..='z', 'a'..='z'); //~ ERROR unreachable pattern
42
43     match 0u8 {
44         5 => {},
45         6 => {},
46         7 => {},
47         8 => {},
48         5..=8 => {}, //~ ERROR unreachable pattern
49         _ => {},
50     }
51     match 0u8 {
52         0..10 => {},
53         10..20 => {},
54         5..15 => {}, //~ ERROR unreachable pattern
55         _ => {},
56     }
57     match 0u8 {
58         0..10 => {},
59         10..20 => {},
60         20..30 => {},
61         5..25 => {}, //~ ERROR unreachable pattern
62         _ => {},
63     }
64     match 0u8 {
65         0..10 => {},
66         10 => {},
67         11..=23 => {},
68         19..30 => {},
69         5..25 => {}, //~ ERROR unreachable pattern
70         _ => {},
71     }
72     match 0usize {
73         0..10 => {},
74         10..20 => {},
75         5..15 => {}, // FIXME: should be unreachable
76         _ => {},
77     }
78     // Chars between '\u{D7FF}' and '\u{E000}' are invalid even though ranges that contain them are
79     // allowed.
80     match 'a' {
81         _ => {},
82         '\u{D7FF}'..='\u{E000}' => {}, //~ ERROR unreachable pattern
83     }
84     match 'a' {
85         '\u{0}'..='\u{D7FF}' => {},
86         '\u{E000}'..='\u{10_FFFF}' => {},
87         '\u{D7FF}'..='\u{E000}' => {}, // FIXME should be unreachable
88     }
89
90     match (0u8, true) {
91         (0..=255, false) => {}
92         (0..=255, true) => {} // ok
93     }
94     match (true, 0u8) {
95         (false, 0..=255) => {}
96         (true, 0..=255) => {} // ok
97     }
98
99     const FOO: i32 = 42;
100     const BAR: &i32 = &42;
101     match &0 {
102         &42 => {}
103         &FOO => {} //~ ERROR unreachable pattern
104         BAR => {} //~ ERROR unreachable pattern
105         _ => {}
106     }
107     // Regression test, see https://github.com/rust-lang/rust/pull/66326#issuecomment-552889933
108     match &0 {
109         BAR => {} // ok
110         _ => {}
111     }
112 }