Closure that only forwards its arguments to a function

ID

rust.maintainability.redundant_closure

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundant Code

Language

Rust

Description

Reports a closure whose whole body is a single call passing its own parameters through unchanged and in the same order, so the closure adds nothing the function name does not already say.

Rationale

The wrapper hides the callee behind a layer the reader has to unpick before seeing that the arguments arrive untouched. It also invites a silent mistake: once parameters are relisted by hand, a later edit can reorder or drop one, and nothing in the shape of the code shows it. Passing the function itself keeps the two sides impossible to get out of step.

The following code illustrates the pattern detected by this rule:

fn double(v: i32) -> i32 {
    v * 2
}

pub fn doubled(values: Vec<i32>) -> Vec<i32> {
    // FLAGGED: Closure that only forwards its arguments to a function
    values.into_iter().map(|v| double(v)).collect()
}

Remediation

Pass the function path directly - map(|v| double(v)) becomes map(double), unwrap_or_else(|| default()) becomes unwrap_or_else(default). Keep the closure when it changes an argument, reorders them, or adapts a method call.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved