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