Skip to content

Commit 00ccadf

Browse files
committed
Add some tests
1 parent e6aa962 commit 00ccadf

File tree

3 files changed

+171
-9
lines changed

3 files changed

+171
-9
lines changed

src/test/ui/or-patterns/exhaustiveness-pass.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,63 @@
66
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
77
fn main() {
88
// Get the fatal error out of the way
9-
match (0u8,) {
9+
match (0,) {
1010
(0 | _,) => {}
1111
//~^ ERROR or-patterns are not fully implemented yet
1212
}
1313

14-
match (0u8,) {
14+
match (0,) {
1515
(1 | 2,) => {}
1616
_ => {}
1717
}
1818

19-
match (0u8,) {
20-
(1 | 1,) => {} // FIXME(or_patterns): redundancy not detected for now.
21-
_ => {}
22-
}
23-
match (0u8, 0u8) {
19+
match (0, 0) {
2420
(1 | 2, 3 | 4) => {}
2521
(1, 2) => {}
26-
(2, 1) => {}
22+
(3, 1) => {}
2723
_ => {}
2824
}
2925
match (Some(0u8),) {
3026
(None | Some(0 | 1),) => {}
3127
(Some(2..=255),) => {}
3228
}
33-
match ((0u8,),) {
29+
match ((0,),) {
3430
((0 | 1,) | (2 | 3,),) => {},
3531
((_,),) => {},
3632
}
3733
match (&[0u8][..],) {
3834
([] | [0 | 1..=255] | [_, ..],) => {},
3935
}
36+
37+
match ((0, 0),) {
38+
((0, 0) | (0, 1),) => {}
39+
_ => {}
40+
}
41+
match ((0, 0),) {
42+
((0, 0) | (1, 0),) => {}
43+
_ => {}
44+
}
45+
46+
// FIXME(or_patterns): Redundancies not detected for now.
47+
match (0,) {
48+
(1 | 1,) => {}
49+
_ => {}
50+
}
51+
match [0; 2] {
52+
[0 | 0, 0 | 0] => {}
53+
_ => {}
54+
}
55+
match &[][..] {
56+
[0] => {}
57+
[0, _] => {}
58+
[0, _, _] => {}
59+
[1, ..] => {}
60+
[1 | 2, ..] => {}
61+
_ => {}
62+
}
63+
match Some(0) {
64+
Some(0) => {}
65+
Some(0 | 1) => {}
66+
_ => {}
67+
}
4068
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#![deny(unreachable_patterns)]
2+
3+
fn main() {
4+
while let 0..=2 | 1 = 0 {} //~ ERROR unreachable pattern
5+
if let 0..=2 | 1 = 0 {} //~ WARN irrefutable if-let pattern
6+
// this one ^ is incorrect
7+
8+
match 0u8 {
9+
0
10+
| 0 => {} //~ ERROR unreachable pattern
11+
_ => {}
12+
}
13+
match Some(0u8) {
14+
Some(0)
15+
| Some(0) => {} //~ ERROR unreachable pattern
16+
_ => {}
17+
}
18+
match (0u8, 0u8) {
19+
(0, _) | (_, 0) => {}
20+
(0, 0) => {} //~ ERROR unreachable pattern
21+
(1, 1) => {}
22+
_ => {}
23+
}
24+
match (0u8, 0u8) {
25+
(0, 1) | (2, 3) => {}
26+
(0, 3) => {}
27+
(2, 1) => {}
28+
_ => {}
29+
}
30+
match (0u8, 0u8) {
31+
(_, 0) | (_, 1) => {}
32+
_ => {}
33+
}
34+
match (0u8, 0u8) {
35+
(0, _) | (1, _) => {}
36+
_ => {}
37+
}
38+
match Some(0u8) {
39+
None | Some(_) => {}
40+
_ => {} //~ ERROR unreachable pattern
41+
}
42+
match Some(0u8) {
43+
None | Some(_) => {}
44+
Some(_) => {} //~ ERROR unreachable pattern
45+
None => {} //~ ERROR unreachable pattern
46+
}
47+
match Some(0u8) {
48+
Some(_) => {}
49+
None => {}
50+
None //~ ERROR unreachable pattern
51+
| Some(_) => {} //~ ERROR unreachable pattern
52+
}
53+
match 0u8 {
54+
1 | 2 => {},
55+
1..=2 => {}, //~ ERROR unreachable pattern
56+
_ => {},
57+
}
58+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
error: unreachable pattern
2+
--> $DIR/top-level-alternation.rs:4:23
3+
|
4+
LL | while let 0..=2 | 1 = 0 {}
5+
| ^
6+
|
7+
note: lint level defined here
8+
--> $DIR/top-level-alternation.rs:1:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
warning: irrefutable if-let pattern
14+
--> $DIR/top-level-alternation.rs:5:20
15+
|
16+
LL | if let 0..=2 | 1 = 0 {}
17+
| ^
18+
|
19+
= note: `#[warn(irrefutable_let_patterns)]` on by default
20+
21+
error: unreachable pattern
22+
--> $DIR/top-level-alternation.rs:10:15
23+
|
24+
LL | | 0 => {}
25+
| ^
26+
27+
error: unreachable pattern
28+
--> $DIR/top-level-alternation.rs:15:15
29+
|
30+
LL | | Some(0) => {}
31+
| ^^^^^^^
32+
33+
error: unreachable pattern
34+
--> $DIR/top-level-alternation.rs:20:9
35+
|
36+
LL | (0, 0) => {}
37+
| ^^^^^^
38+
39+
error: unreachable pattern
40+
--> $DIR/top-level-alternation.rs:40:9
41+
|
42+
LL | _ => {}
43+
| ^
44+
45+
error: unreachable pattern
46+
--> $DIR/top-level-alternation.rs:44:9
47+
|
48+
LL | Some(_) => {}
49+
| ^^^^^^^
50+
51+
error: unreachable pattern
52+
--> $DIR/top-level-alternation.rs:45:9
53+
|
54+
LL | None => {}
55+
| ^^^^
56+
57+
error: unreachable pattern
58+
--> $DIR/top-level-alternation.rs:50:9
59+
|
60+
LL | None
61+
| ^^^^
62+
63+
error: unreachable pattern
64+
--> $DIR/top-level-alternation.rs:51:15
65+
|
66+
LL | | Some(_) => {}
67+
| ^^^^^^^
68+
69+
error: unreachable pattern
70+
--> $DIR/top-level-alternation.rs:55:9
71+
|
72+
LL | 1..=2 => {},
73+
| ^^^^^
74+
75+
error: aborting due to 10 previous errors
76+

0 commit comments

Comments
 (0)