Rust logoRust/
RS-W1129

Found explicitly ignored unit valueRS-W1129

Minor severityMinor
Anti-pattern categoryAnti-pattern

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
}
fn foo() {}
fn main() {
    (); // fine
    foo(); // fine
}