Skip to content

Commit 0881750

Browse files
committed
Move tests to ui, split them and add some
1 parent cdc844e commit 0881750

6 files changed

+192
-18
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(or_patterns)]
2+
#![feature(slice_patterns)]
3+
#![allow(incomplete_features)]
4+
#![deny(unreachable_patterns)]
5+
6+
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
7+
fn main() {
8+
// Get the fatal error out of the way
9+
match (0u8,) {
10+
(0 | _,) => {}
11+
//~^ ERROR or-patterns are not fully implemented yet
12+
}
13+
14+
match (0u8, 0u8) {
15+
//~^ ERROR non-exhaustive patterns: `(2u8..=std::u8::MAX, _)`
16+
(0 | 1, 2 | 3) => {}
17+
}
18+
match ((0u8,),) {
19+
//~^ ERROR non-exhaustive patterns: `((4u8..=std::u8::MAX))`
20+
((0 | 1,) | (2 | 3,),) => {},
21+
}
22+
match (Some(0u8),) {
23+
//~^ ERROR non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))`
24+
(None | Some(0 | 1),) => {}
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0004]: non-exhaustive patterns: `(2u8..=std::u8::MAX, _)` not covered
2+
--> $DIR/exhaustiveness-non-exhaustive.rs:14:11
3+
|
4+
LL | match (0u8, 0u8) {
5+
| ^^^^^^^^^^ pattern `(2u8..=std::u8::MAX, _)` not covered
6+
|
7+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8+
9+
error[E0004]: non-exhaustive patterns: `((4u8..=std::u8::MAX))` not covered
10+
--> $DIR/exhaustiveness-non-exhaustive.rs:18:11
11+
|
12+
LL | match ((0u8,),) {
13+
| ^^^^^^^^^ pattern `((4u8..=std::u8::MAX))` not covered
14+
|
15+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
16+
17+
error[E0004]: non-exhaustive patterns: `(Some(2u8..=std::u8::MAX))` not covered
18+
--> $DIR/exhaustiveness-non-exhaustive.rs:22:11
19+
|
20+
LL | match (Some(0u8),) {
21+
| ^^^^^^^^^^^^ pattern `(Some(2u8..=std::u8::MAX))` not covered
22+
|
23+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
24+
25+
error: or-patterns are not fully implemented yet
26+
--> $DIR/exhaustiveness-non-exhaustive.rs:10:10
27+
|
28+
LL | (0 | _,) => {}
29+
| ^^^^^
30+
31+
error: aborting due to 4 previous errors
32+
33+
For more information about this error, try `rustc --explain E0004`.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![feature(or_patterns)]
2+
#![feature(slice_patterns)]
3+
#![allow(incomplete_features)]
4+
#![deny(unreachable_patterns)]
5+
6+
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
7+
fn main() {
8+
// Get the fatal error out of the way
9+
match (0u8,) {
10+
(0 | _,) => {}
11+
//~^ ERROR or-patterns are not fully implemented yet
12+
}
13+
14+
match (0u8,) {
15+
(1 | 2,) => {}
16+
_ => {}
17+
}
18+
19+
match (0u8,) {
20+
(1 | 1,) => {} // redundancy not detected for now
21+
_ => {}
22+
}
23+
match (0u8, 0u8) {
24+
(1 | 2, 3 | 4) => {}
25+
(1, 2) => {}
26+
(2, 1) => {}
27+
_ => {}
28+
}
29+
match (Some(0u8),) {
30+
(None | Some(0 | 1),) => {}
31+
(Some(2..=255),) => {}
32+
}
33+
match ((0u8,),) {
34+
((0 | 1,) | (2 | 3,),) => {},
35+
((_,),) => {},
36+
}
37+
match (&[0u8][..],) {
38+
([] | [0 | 1..=255] | [_, ..],) => {},
39+
}
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: or-patterns are not fully implemented yet
2+
--> $DIR/exhaustiveness-pass.rs:10:10
3+
|
4+
LL | (0 | _,) => {}
5+
| ^^^^^
6+
7+
error: aborting due to previous error
8+

src/test/compile-fail/or-patterns.rs renamed to src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@
33
#![allow(incomplete_features)]
44
#![deny(unreachable_patterns)]
55

6+
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
67
fn main() {
7-
// We wrap patterns in a tuple because top-level or-patterns are special-cased for now.
8-
98
// Get the fatal error out of the way
109
match (0u8,) {
1110
(0 | _,) => {}
1211
//~^ ERROR or-patterns are not fully implemented yet
1312
}
1413

15-
match (0u8,) {
16-
(1 | 2,) => {}
17-
_ => {}
18-
}
19-
2014
match (0u8,) {
2115
(1 | 2,) => {}
2216
(1,) => {} //~ ERROR unreachable pattern
@@ -33,32 +27,25 @@ fn main() {
3327
(1 | 2,) => {} //~ ERROR unreachable pattern
3428
_ => {}
3529
}
36-
match (0u8,) {
37-
(1 | 1,) => {} // redundancy not detected for now
38-
_ => {}
39-
}
4030
match (0u8, 0u8) {
4131
(1 | 2, 3 | 4) => {}
42-
(1, 2) => {}
4332
(1, 3) => {} //~ ERROR unreachable pattern
4433
(1, 4) => {} //~ ERROR unreachable pattern
4534
(2, 4) => {} //~ ERROR unreachable pattern
4635
(2 | 1, 4) => {} //~ ERROR unreachable pattern
36+
(1, 5 | 6) => {}
37+
(1, 4 | 5) => {} //~ ERROR unreachable pattern
4738
_ => {}
4839
}
4940
match (Some(0u8),) {
5041
(None | Some(1 | 2),) => {}
5142
(Some(1),) => {} //~ ERROR unreachable pattern
5243
(None,) => {} //~ ERROR unreachable pattern
53-
(Some(_),) => {}
44+
_ => {}
5445
}
5546
match ((0u8,),) {
5647
((1 | 2,) | (3 | 4,),) => {},
5748
((1..=4,),) => {}, //~ ERROR unreachable pattern
58-
((_,),) => {},
59-
}
60-
match (&[0u8][..],) {
61-
([] | [0 | 1..=255] | [_, ..],) => {},
62-
(_,) => {}, //~ ERROR unreachable pattern
49+
_ => {},
6350
}
6451
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
error: unreachable pattern
2+
--> $DIR/exhaustiveness-unreachable-pattern.rs:16:9
3+
|
4+
LL | (1,) => {}
5+
| ^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/exhaustiveness-unreachable-pattern.rs:4:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: unreachable pattern
14+
--> $DIR/exhaustiveness-unreachable-pattern.rs:21:9
15+
|
16+
LL | (2,) => {}
17+
| ^^^^
18+
19+
error: unreachable pattern
20+
--> $DIR/exhaustiveness-unreachable-pattern.rs:27:9
21+
|
22+
LL | (1 | 2,) => {}
23+
| ^^^^^^^^
24+
25+
error: unreachable pattern
26+
--> $DIR/exhaustiveness-unreachable-pattern.rs:32:9
27+
|
28+
LL | (1, 3) => {}
29+
| ^^^^^^
30+
31+
error: unreachable pattern
32+
--> $DIR/exhaustiveness-unreachable-pattern.rs:33:9
33+
|
34+
LL | (1, 4) => {}
35+
| ^^^^^^
36+
37+
error: unreachable pattern
38+
--> $DIR/exhaustiveness-unreachable-pattern.rs:34:9
39+
|
40+
LL | (2, 4) => {}
41+
| ^^^^^^
42+
43+
error: unreachable pattern
44+
--> $DIR/exhaustiveness-unreachable-pattern.rs:35:9
45+
|
46+
LL | (2 | 1, 4) => {}
47+
| ^^^^^^^^^^
48+
49+
error: unreachable pattern
50+
--> $DIR/exhaustiveness-unreachable-pattern.rs:37:9
51+
|
52+
LL | (1, 4 | 5) => {}
53+
| ^^^^^^^^^^
54+
55+
error: unreachable pattern
56+
--> $DIR/exhaustiveness-unreachable-pattern.rs:42:9
57+
|
58+
LL | (Some(1),) => {}
59+
| ^^^^^^^^^^
60+
61+
error: unreachable pattern
62+
--> $DIR/exhaustiveness-unreachable-pattern.rs:43:9
63+
|
64+
LL | (None,) => {}
65+
| ^^^^^^^
66+
67+
error: unreachable pattern
68+
--> $DIR/exhaustiveness-unreachable-pattern.rs:48:9
69+
|
70+
LL | ((1..=4,),) => {},
71+
| ^^^^^^^^^^^
72+
73+
error: or-patterns are not fully implemented yet
74+
--> $DIR/exhaustiveness-unreachable-pattern.rs:10:10
75+
|
76+
LL | (0 | _,) => {}
77+
| ^^^^^
78+
79+
error: aborting due to 12 previous errors
80+

0 commit comments

Comments
 (0)