-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add unneeded-wildcard-pattern
lint
#4537
Conversation
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.
Implementation LGTM.
But I'm concerned, that _, ..
/.., _
and ..
isn't quite the same. While the _, ..
means, there is at least one more variant in this struct/tuple, ..
means, there are 0 or more variants in this struct/tuple:
struct TS(u32, u32);
fn main() {
let a = TS(1, 2);
match a {
TS(_, _, ..) => (),
};
}
compiles just fine.
If we'd remove a field from the struct, this code would error, while the ..
variant, would still compile. I don't think, this could really lead to an error, since the fields aren't used anyway, but I would add the difference between _, ..
and ..
at least as a note to the lint documentation (not necessarily to the Known Problems section).
Fix grammar errors and use `Pat::is_rest` instead of own function.
I made all the changes suggested apart from adding a note between the difference between If anyone wants to fork this branch and finish that off, I'm happy to pull the changes. (Maintainers can, of course, just push to this branch directly.) |
if let (0, _, _, ..) = t {}; | ||
if let (0, .., _, _) = t {}; | ||
if let (_, 0, ..) = t {}; | ||
if let (.., 0, _) = t {}; |
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.
if let (_, .., 2, 3) = t {}
doesn't get linted, does it? Can you add a test for it? This could actually lead to refactoring errors, because with the _, ..
it means, there is at least one element before the 2
.
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.
It absolutely will. This is the purpose of this lint.
What errors could this lead to and how is this different from the case (0, .., _, _)
→(0, ..)
?
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 can't remember what I had in mind. And I also cannot come up with something. Can you add a test for it though?
Co-Authored-By: Philipp Krones <hello@philkrones.com>
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.
Only a test for the _, .., 0
case is missing.
☔ The latest upstream changes (presumably #4511) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ |
📌 Commit ca6d36b has been approved by |
Add `unneeded-wildcard-pattern` lint changelog: Add `unneeded-wildcard-pattern` lint
☀️ Test successful - checks-travis, status-appveyor |
changelog: Add
unneeded-wildcard-pattern
lint