-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Detect const in pattern with typo #132658
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in match checking cc @Nadrieril |
@@ -966,7 +974,10 @@ fn report_unreachable_pattern<'p, 'tcx>( | |||
}); | |||
} | |||
[covering_pat] if pat_is_catchall(covering_pat) => { | |||
lint.covered_by_catchall = Some(covering_pat.data().span); | |||
// A binding pattern that matches all, a single binding name. |
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.
This comment is incorrect: pat_is_catchall
also accepts patterns such as (a, b)
or Struct { field, .. }
. If you want only the case of a single binding/wildcard, check instead that pat.ctor()
is Constructor::Wildcard
. I'm thinking we should rename that function to pat_catches_all
tbh.
☔ The latest upstream changes (presumably #133212) made this pull request unmergeable. Please resolve the merge conflicts. |
When writing a constant name incorrectly in a pattern, the pattern will be identified as a new binding. We look for consts in the current crate, consts that where imported in the current crate and for local `let` bindings in case someone got them confused with `const`s. ``` error: unreachable pattern --> $DIR/const-with-typo-in-pattern-binding.rs:30:9 | LL | GOOOD => {} | ----- matches any value LL | LL | _ => {} | ^ no value can reach this | help: you might have meant to pattern match against the value of similarly named constant `GOOD` instead of introducing a new catch-all binding | LL | GOOD => {} | ~~~~ ``` Fix rust-lang#132582.
ab19d0a
to
2487765
Compare
Alright, the diagnostic wins are quite good and I can't think of a better way. Thanks for the work! @bors r+ |
When writing a constant name incorrectly in a pattern, the pattern will be identified as a new binding. We look for consts in the current crate, consts that where imported in the current crate and for local
let
bindings in case someone got them confused withconst
s.Fix #132582.