Binding created only to be returned on the next line

ID

rust.maintainability.let_and_return

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundant Code

Language

Rust

Description

Reports a let binding whose only use is the expression that immediately follows it, either as the block’s tail expression or as an explicit return. The binding exists for one line and then disappears.

Rationale

The extra name is a step the reader has to follow to find out that nothing happens to the value. It also invites a later editor to insert code between the binding and the return that silently changes what is returned, and it can extend a borrow past the point where the block ends.

The following code illustrates the pattern detected by this rule:

pub fn doubled(v: i32) -> i32 {
    // FLAGGED: Binding created only to be returned on the next line
    let result = v * 2;
    result
}

Remediation

Return the expression directly: let x = compute(); x becomes compute(). Keep the binding only when its name documents something the expression does not.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved