Rust

Rust

Made by DeepSource

Found explicitly ignored unit value RS-W1129

Anti-pattern
Minor

The () type, also called “unit”, has exactly one value (), and is used when there is no other meaningful value that could be returned. It is most commonly seen implicitly: functions without a -> implicitly have return type (), that is, these are equivalent:

fn foo() {}
// vs,
fn foo() -> () {}

Hence explicitly ignoring values of unit type is redundant.

Bad practice

fn foo() {}
fn main() {
    let _ = (); // bad
    let _ = foo(); // bad
}

Recommended

fn foo() {}
fn main() {
    (); // fine
    foo(); // fine
}