Suggest collapsing nested or patterns if the MSRV allows it#12745
Conversation
| Arm { | ||
| pat: Pat { | ||
| kind: PatKind::Wild, .. | ||
| }, | ||
| .. | ||
| }, |
There was a problem hiding this comment.
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
orpatterns 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