-
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 Collapsible match lint #6402
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
Hmm my stderr is too long? I'm not sure what to do about that. |
How about splitting a test file into two? |
Done. |
Good stuff! I especially like the |
📌 Commit 0e20788 has been approved by |
Add Collapsible match lint changelog: Add collapsible_match lint Closes #1252 Closes #2521 This lint finds nested `match` or `if let` patterns that can be squashed together. It is designed to be very conservative to only find cases where merging the patterns would most likely reduce cognitive complexity. Example: ```rust match result { Ok(opt) => match opt { Some(x) => x, _ => return, } _ => return, } ``` to ```rust match result { Ok(Some(x)) => x, _ => return, } ``` These criteria must be met for the lint to fire: * The inner match has exactly 2 branches. * Both the outer and inner match have a "wild" branch like `_ => ..`. There is a special case for `None => ..` to also be considered "wild-like". * The contents of the wild branches are identical. * The binding which "links" the matches is never used elsewhere. Thanks to the hir, `if let`'s are easily included with this lint since they are desugared into equivalent `match`'es. I think this would fit into the style category, but I would also understand changing it to pedantic.
💔 Test failed - checks-action_test |
@bors retry rollup |
Rollup of 4 pull requests Successful merges: - #6308 (add `internal-lints` feature to enable clippys internal lints (off by default)) - #6395 (switch Version/VersionReq usages to RustcVersion ) - #6402 (Add Collapsible match lint) - #6407 (CONTRIBUTING: update bors queue url from buildbot2.rlo to bors.rlo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup changelog: rollup
changelog: Add collapsible_match lint
Closes #1252
Closes #2521
This lint finds nested
match
orif let
patterns that can be squashed together. It is designed to be very conservative to only find cases where merging the patterns would most likely reduce cognitive complexity.Example:
to
These criteria must be met for the lint to fire:
_ => ..
. There is a special case forNone => ..
to also be considered "wild-like".Thanks to the hir,
if let
's are easily included with this lint since they are desugared into equivalentmatch
'es.I think this would fit into the style category, but I would also understand changing it to pedantic.