let
bindings in the form of if-let
and while-let
expressions are unnecessary unless they contain a pattern capture.
Consider using the matches!
macro or testing equality ==
instead. Since the matches!
macro was introduced in 1.42, this issue is raised only if the msrv
flag in your .deepsource.toml
file is set accordingly.
fn main() {
if let Some(1) = foo() {}
if let Bar(_) = bar() {}
}
// or,
enum EnumABC { A(i32), B(u32), C(&'static str) }
fn bar() -> EnumABC { EnumABC::B(10u32) }
fn foo() {
let EnumABC::A(_) = bar() else { return None; }
}
fn main() {
if foo() == Some(1) {}
if matches!(bar(), Bar(_)) {}
}
// or,
enum EnumABC { A(i32), B(u32), C(&'static str) }
fn bar() -> EnumABC { EnumABC::B(10u32) }
fn foo() {
if !matches!(bar(), EnumABC::A(_)) { return None; }
}