Add some tests
This commit is contained in:
parent
f1b882b558
commit
fa4a4d3eda
7 changed files with 91 additions and 3 deletions
|
|
@ -0,0 +1,15 @@
|
|||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
const C0: &'static [u8] = b"\x00";
|
||||
|
||||
fn main() {
|
||||
let x: &[u8] = &[0];
|
||||
match x {
|
||||
&[] => {}
|
||||
&[1..=255] => {}
|
||||
// this shouldn't be unreachable
|
||||
C0 => {} //~ unreachable pattern
|
||||
&[_, _, ..] => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:12:9
|
||||
|
|
||||
LL | C0 => {}
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:2:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -44,4 +44,11 @@ fn main() {
|
|||
b"" => (), //~ ERROR unreachable pattern
|
||||
_ => (), //~ ERROR unreachable pattern
|
||||
}
|
||||
|
||||
const CONST1: &[bool; 1] = &[true];
|
||||
match &[false] {
|
||||
CONST1 => {}
|
||||
[true] => {} //~ ERROR unreachable pattern
|
||||
[false] => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,11 @@ error: unreachable pattern
|
|||
LL | _ => (),
|
||||
| ^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: unreachable pattern
|
||||
--> $DIR/slice-pattern-const.rs:51:9
|
||||
|
|
||||
LL | [true] => {}
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -82,4 +82,26 @@ fn main() {
|
|||
[_, _] => {}
|
||||
[false, .., false] => {}
|
||||
}
|
||||
|
||||
const CONST: &[bool] = &[true];
|
||||
match s {
|
||||
//~^ ERROR `&[..]` not covered
|
||||
CONST => {}
|
||||
}
|
||||
match s {
|
||||
//~^ ERROR `&[true]` not covered
|
||||
[] => {},
|
||||
[false] => {},
|
||||
CONST => {},
|
||||
[_, _, ..] => {}
|
||||
}
|
||||
const CONST1: &[bool; 1] = &[true];
|
||||
match s1 {
|
||||
//~^ ERROR `&[..]` not covered
|
||||
CONST1 => {}
|
||||
}
|
||||
match s1 {
|
||||
CONST1 => {}
|
||||
[false] => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,30 @@ LL | match s {
|
|||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error[E0004]: non-exhaustive patterns: `&[..]` not covered
|
||||
--> $DIR/slice-patterns-exhaustiveness.rs:87:11
|
||||
|
|
||||
LL | match s {
|
||||
| ^ pattern `&[..]` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&[true]` not covered
|
||||
--> $DIR/slice-patterns-exhaustiveness.rs:91:11
|
||||
|
|
||||
LL | match s {
|
||||
| ^ pattern `&[true]` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&[..]` not covered
|
||||
--> $DIR/slice-patterns-exhaustiveness.rs:99:11
|
||||
|
|
||||
LL | match s1 {
|
||||
| ^^ pattern `&[..]` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
let s: &[bool] = &[true; 0];
|
||||
let s: &[bool] = &[];
|
||||
|
||||
match s {
|
||||
[true, ..] => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue