Rust

Rust

By DeepSource

Found pointer comparison with ptr::null() RS-C1014

Anti-pattern Autofix

Comparisons between ptr::null() and pointer (*T) are considered non-idiomatic. The inbuilt is_null() method on pointer(*T) types is equivalent to explicitly comparing against ptr::null().

Consider replacing the comparison with is_null().

Bad practice

fn foo() {
    let x = Some(1);
    if x != ptr::null() {
        // ...
    }
}

Recommended

fn foo {
    let x = Some(1);
    if !x.is_null() {
        // ...
    }
}