-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail gracefully when const pattern is not structural match.
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[derive(PartialEq)] | ||
enum E { | ||
A, | ||
} | ||
|
||
const E_SL: &[E] = &[E::A]; | ||
|
||
fn main() { | ||
match &[][..] { | ||
//~^ ERROR non-exhaustive patterns: `&_` not covered [E0004] | ||
E_SL => {} | ||
//~^ WARN to use a constant of type `E` in a pattern, `E` must be annotated with `#[derive(PartialEq, Eq)]` | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/consts/const_in_pattern/incomplete-slice.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
warning: to use a constant of type `E` in a pattern, `E` must be annotated with `#[derive(PartialEq, Eq)]` | ||
--> $DIR/incomplete-slice.rs:11:9 | ||
| | ||
LL | E_SL => {} | ||
| ^^^^ | ||
| | ||
= note: `#[warn(indirect_structural_match)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411> | ||
|
||
error[E0004]: non-exhaustive patterns: `&_` not covered | ||
--> $DIR/incomplete-slice.rs:9:11 | ||
| | ||
LL | match &[][..] { | ||
| ^^^^^^^ pattern `&_` not covered | ||
| | ||
= note: the matched value is of type `&[E]` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | ||
| | ||
LL ~ E_SL => {} | ||
LL + &_ => todo!() | ||
| | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0004`. |