Rollup merge of #79072 - oli-obk:byte_str_pat, r=estebank
Fix exhaustiveness in case a byte string literal is used at slice type fixes #79048
This commit is contained in:
commit
b6f52410bb
7 changed files with 113 additions and 12 deletions
36
src/test/ui/match/type_polymorphic_byte_str_literals.rs
Normal file
36
src/test/ui/match/type_polymorphic_byte_str_literals.rs
Normal 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() {}
|
||||
21
src/test/ui/match/type_polymorphic_byte_str_literals.stderr
Normal file
21
src/test/ui/match/type_polymorphic_byte_str_literals.stderr
Normal 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`.
|
||||
|
|
@ -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]`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue