Closed
Description
Sorry about the long title 😅
Given the following code (playground):
fn main() {
let x: usize = 4;
let y = Some(x);
match x {
0 => (),
1..=usize::MAX => (),
}
match y {
Some(0) => (),
Some(1..=usize::MAX) => (),
None => (),
}
}
The current output is:
error[E0004]: non-exhaustive patterns: `_` not covered
--> src/main.rs:5:11
|
5 | match x {
| ^ 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 `usize`
= note: `usize` does not have a fixed maximum value, so a wildcard `_` is necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
error[E0004]: non-exhaustive patterns: `Some(_)` not covered
--> src/main.rs:10:11
|
10 | match y {
| ^ pattern `Some(_)` 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 `Option<usize>`
Note how the first diagnostic, emitted when matching on a usize
, contains additional information about why this exhaustive match does not pass the exhaustiveness check. Ideally, this information should be added to the second diagnostic as well:
error[E0004]: non-exhaustive patterns: `Some(_)` not covered
--> src/main.rs:10:11
|
10 | match y {
| ^ pattern `Some(_)` 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 `Option<usize>`
= note: `usize` does not have a fixed maximum value, so a wildcard `_` is necessary to match exhaustively
= help: add `#![feature(precise_pointer_size_matching)]` to the crate attributes to enable precise `usize` matching
@rustbot modify labels: +A-exhaustiveness-checking +A-patterns +D-terse
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsRelating to exhaustiveness / usefulness checking of patternsRelating to patterns and pattern matchingDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.