-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Suggest collapsing nested or patterns if the MSRV allows it #12745
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
Conversation
Arm { | ||
pat: Pat { | ||
kind: PatKind::Wild, .. | ||
}, | ||
.. | ||
}, |
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 didn't look right. It seems like the intention was to catch if matches!
, but because of the way it was written it would still emit a warning on a manually written match
that happens to have the same pattern structure but does something in the _ => ...
arm that's semantically different. Changed it to look for the matches!
macro and added a test case for a false positive that this fixes.
Also one thing I've noticed, these two lints if let Some(v) = Some(42) {
if v == 42 {}
} and suggest |
Agreed, unifying those lints will improve functionality and performance. I'll look forward to a follow-up PR. This one already looks merge-worthy, so thank you for improving clippy! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Nested
or
patterns have been stable since 1.53, so we should be able to suggestSome(1 | 2)
if the MSRV isn't set below that.This change adds an msrv check and also moves it to
matches/mod.rs
, because it's also needed byredundant_guards
.changelog: [
collapsible_match
]: suggest collapsing nested or patterns if the MSRV allows it