Skip to content

Commit fa4a4d3

Browse files
committed
Add some tests
1 parent f1b882b commit fa4a4d3

7 files changed

+91
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(slice_patterns)]
2+
#![deny(unreachable_patterns)]
3+
4+
const C0: &'static [u8] = b"\x00";
5+
6+
fn main() {
7+
let x: &[u8] = &[0];
8+
match x {
9+
&[] => {}
10+
&[1..=255] => {}
11+
// this shouldn't be unreachable
12+
C0 => {} //~ unreachable pattern
13+
&[_, _, ..] => {}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unreachable pattern
2+
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:12:9
3+
|
4+
LL | C0 => {}
5+
| ^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:2:9
9+
|
10+
LL | #![deny(unreachable_patterns)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

src/test/ui/pattern/usefulness/slice-pattern-const.rs

+7
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ fn main() {
4444
b"" => (), //~ ERROR unreachable pattern
4545
_ => (), //~ ERROR unreachable pattern
4646
}
47+
48+
const CONST1: &[bool; 1] = &[true];
49+
match &[false] {
50+
CONST1 => {}
51+
[true] => {} //~ ERROR unreachable pattern
52+
[false] => {}
53+
}
4754
}

src/test/ui/pattern/usefulness/slice-pattern-const.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ error: unreachable pattern
5252
LL | _ => (),
5353
| ^
5454

55-
error: aborting due to 8 previous errors
55+
error: unreachable pattern
56+
--> $DIR/slice-pattern-const.rs:51:9
57+
|
58+
LL | [true] => {}
59+
| ^^^^^^
60+
61+
error: aborting due to 9 previous errors
5662

src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.rs

+22
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,26 @@ fn main() {
8282
[_, _] => {}
8383
[false, .., false] => {}
8484
}
85+
86+
const CONST: &[bool] = &[true];
87+
match s {
88+
//~^ ERROR `&[..]` not covered
89+
CONST => {}
90+
}
91+
match s {
92+
//~^ ERROR `&[true]` not covered
93+
[] => {},
94+
[false] => {},
95+
CONST => {},
96+
[_, _, ..] => {}
97+
}
98+
const CONST1: &[bool; 1] = &[true];
99+
match s1 {
100+
//~^ ERROR `&[..]` not covered
101+
CONST1 => {}
102+
}
103+
match s1 {
104+
CONST1 => {}
105+
[false] => {}
106+
}
85107
}

src/test/ui/pattern/usefulness/slice-patterns-exhaustiveness.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ LL | match s {
102102
|
103103
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
104104

105-
error: aborting due to 13 previous errors
105+
error[E0004]: non-exhaustive patterns: `&[..]` not covered
106+
--> $DIR/slice-patterns-exhaustiveness.rs:87:11
107+
|
108+
LL | match s {
109+
| ^ pattern `&[..]` not covered
110+
|
111+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
112+
113+
error[E0004]: non-exhaustive patterns: `&[true]` not covered
114+
--> $DIR/slice-patterns-exhaustiveness.rs:91:11
115+
|
116+
LL | match s {
117+
| ^ pattern `&[true]` not covered
118+
|
119+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
120+
121+
error[E0004]: non-exhaustive patterns: `&[..]` not covered
122+
--> $DIR/slice-patterns-exhaustiveness.rs:99:11
123+
|
124+
LL | match s1 {
125+
| ^^ pattern `&[..]` not covered
126+
|
127+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
128+
129+
error: aborting due to 16 previous errors
106130

107131
For more information about this error, try `rustc --explain E0004`.

src/test/ui/pattern/usefulness/slice-patterns-reachability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![deny(unreachable_patterns)]
33

44
fn main() {
5-
let s: &[bool] = &[true; 0];
5+
let s: &[bool] = &[];
66

77
match s {
88
[true, ..] => {}

0 commit comments

Comments
 (0)