Fix exhaustiveness in case a byte string literal is used at slice type

This commit is contained in:
oli 2020-11-15 13:04:30 +00:00
parent 30e49a9ead
commit a1cdf722f4
7 changed files with 113 additions and 12 deletions

View file

@ -0,0 +1,36 @@
#[deny(unreachable_patterns)]
fn parse_data1(data: &[u8]) -> u32 {
match data {
b"" => 1,
_ => 2,
}
}
fn parse_data2(data: &[u8]) -> u32 {
match data { //~ ERROR non-exhaustive patterns: `&[_, ..]` not covered
b"" => 1,
}
}
fn parse_data3(data: &[u8; 0]) -> u8 {
match data {
b"" => 1,
}
}
fn parse_data4(data: &[u8]) -> u8 {
match data { //~ ERROR non-exhaustive patterns
b"aaa" => 0,
[_, _, _] => 1,
}
}
fn parse_data5(data: &[u8; 3]) -> u8 {
match data {
b"aaa" => 0,
[_, _, _] => 1,
}
}
fn main() {}

View file

@ -0,0 +1,21 @@
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
--> $DIR/type_polymorphic_byte_str_literals.rs:11:11
|
LL | match data {
| ^^^^ pattern `&[_, ..]` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8]`
error[E0004]: non-exhaustive patterns: `&[]`, `&[_]`, `&[_, _]` and 1 more not covered
--> $DIR/type_polymorphic_byte_str_literals.rs:23:11
|
LL | match data {
| ^^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 1 more not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8]`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0004`.

View file

@ -7,11 +7,11 @@ LL | match buf {
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8; 4]`
error[E0004]: non-exhaustive patterns: `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered
error[E0004]: non-exhaustive patterns: `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
--> $DIR/match-byte-array-patterns-2.rs:10:11
|
LL | match buf {
| ^^^ patterns `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered
| ^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8]`