-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
A-lintArea: New lintsArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Checks for if let
for pattern
s that can be re-written with matches!
This can be an improvement to equatable_if_let
lint.
For background see #9102 (comment)
Lint Name
No response
Category
No response
Advantage
Similar to equatable_if_let
:
- It reads better and has less cognitive load because equality won’t cause binding.
- It avoids a Yoda condition.
- Equality is a simple bool expression and can be merged with && and || and reuse if blocks
Drawbacks
No response
Example
#![allow(dead_code)]
enum Foo {
Bar,
Baz,
}
fn test(foo: Foo) {
if let Foo::Baz = foo {
println!("Foo::Baz");
}
}
can be written as
#![allow(dead_code)]
enum Foo {
Bar,
Baz,
}
fn test(foo: Foo) {
if matches!(foo, Foo::Baz) {
println!("Foo::Baz");
}
}
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy