-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check_match: refactor + improve non-exhaustive diagnostics for default binding modes #64271
Conversation
LL | | None, | ||
LL | | | ||
LL | | } | ||
| |_- `Opt` defined here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E0005 seem to not be pointing at the uncovered variants. This should also have at least a note about if let
. I'll take a look at the code tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wondered if that was by-design or not. If not, this would actually simplify the code and I think I know how to fix it. There's a good argument for why it should be by-design without full or-patterns but we will have those on nightly soon so that argument is probably invalid now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be ok to unify both, maybe with some extra help
about how to write or-patterns (only if all variants have the currently covered field types), otherwise talk about if let
. But this could be done as follow up work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've unified them a bit but I'd like to punt on the extra help
or referring to if let
. A follow up issue might be good to file however.
LL | | None, | ||
LL | | | ||
LL | | } | ||
| |_- `Opt` defined here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be ok to unify both, maybe with some extra help
about how to write or-patterns (only if all variants have the currently covered field types), otherwise talk about if let
. But this could be done as follow up work.
335b855
to
eeca6ee
Compare
@bors r+ |
📌 Commit 20a2605 has been approved by |
check_match: refactor + improve non-exhaustive diagnostics for default binding modes Refactor `check_match` a bit with more code-reuse and improve the diagnostics for a non-exhaustive pattern match by peeling off any references from the scrutinee type so that the "defined here" label is added in more cases. For example: ```rust error[E0004]: non-exhaustive patterns: `&mut &B` not covered --> foo.rs:4:11 | 1 | enum E { A, B } | --------------- | | | | | not covered | `E` defined here ... 4 | match x { | ^ pattern `&mut &B` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms ``` Moreover, wrt. "defined here", we give irrefutable pattern matching (i.e. in `let`, `for`, and `fn` parameters) a more consistent treatment in line with `match`. r? @estebank
☀️ Test successful - checks-azure |
Tested on commit rust-lang/rust@f0b58fc. Direct link to PR: <rust-lang/rust#64271> 🎉 rls on linux: test-fail → test-pass (cc @Xanewok, @rust-lang/infra).
Refactor
check_match
a bit with more code-reuse and improve the diagnostics for a non-exhaustive pattern match by peeling off any references from the scrutinee type so that the "defined here" label is added in more cases. For example:Moreover, wrt. "defined here", we give irrefutable pattern matching (i.e. in
let
,for
, andfn
parameters) a more consistent treatment in line withmatch
.r? @estebank