rust-lang / rust-lang/rust-clippy
New lint: collapsible `matches!`-es
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
replaces multiple matches!() on the same variable with one that has all the patterns combined
Advantage
- More concise
- (Potentially) less work for the optimizer
Drawbacks
No response
Example
enum Foo {
Bar, Baz
}
let f = Foo::Bar;
let _ = matches!(f, Foo::Bar) || matches!(f, Foo::Baz);
Could be written as:
/* snip */
let _ = matches!(f, Foo::Bar | Foo::Baz);
Comparison with existing lints
no similar lints
Additional Context
would be a bit difficult to implement since one'd need to look at the pre-expansion source
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading clippy_lints/src/floating_point_arithmetic.rs around line 495 and trace how the existing related pattern is recognized. Investigate how Clippy accesses pre-expansion source, then define the lint behavior for multiple matches! calls on one variable, including the combined-pattern example; done means the proposed case is detected without false matches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100