named binding of the unit value

ID

rust.maintainability.let_unit_value

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundancy

Language

Rust

Description

Reports a named let binding whose value is the unit () - either the literal or an expression declared as (). The _ discard pattern is not reported, since it is the deliberate way to drop a value.

Rationale

A name promises a value worth referring to, and () carries none, so every later use of the binding is either dead or a mistake waiting for the expression to start returning something. The usual cause is a function whose return type changed to (), or a semicolon that turned the intended result into a statement - both leave code that compiles and quietly computes nothing.

The following code illustrates the pattern detected by this rule:

fn flush(buffer: &mut Vec<u8>) {
    buffer.clear();
}

fn prepare(buffer: &mut Vec<u8>) -> usize {
    // FLAGGED: named binding of the unit value
    let done = ();
    // FLAGGED: named binding of the unit value
    let flushed: () = flush(buffer);
    let _ = (done, flushed);
    buffer.len()
}

Remediation

Call the expression as a plain statement and drop the binding. If the value was meant to be used, remove the trailing semicolon inside the function or block that produced it so it returns the result. Use let _ = …​ only when a value is deliberately discarded.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved