Rust

Rust

Made by DeepSource

Found comparison with None RS-W1108

Anti-pattern
Minor
Autofix

Checking if a value is None via a direct comparison is usually inspired from other programming languages (e.g. foo is None in Python). In Rust, the Eq trait is used to perform the comparison, which is unneeded. The Option type provides the is_none() and is_some() methods which return a boolean, allowing for more idoimatic comparison.

Bad practice

fn foo() {
    if bar == None {
        // ...
    }
    if bar != None {
        // ...
    }
}

Recommended

fn foo() {
    if bar.is_none() {
        // ...
    }
    if bar.is_some() {
        // ...
    }
}