Closed
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");
}
}