map with a closure that only clones or dereferences

ID

rust.performance.map_clone

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Inefficient Api Usage

Language

Rust

Description

This closure only clones or dereferences its argument, which cloned() (or copied() for Copy items) expresses directly. On an Option use cloned()/copied() as well. The shorter form states the intent and lets the compiler pick the cheapest copy.

Rationale

This closure only clones or dereferences its argument, which cloned() (or copied() for Copy items) expresses directly. On an Option use cloned()/copied() as well. The shorter form states the intent and lets the compiler pick the cheapest copy.

The following code illustrates the pattern detected by this rule:

fn names(source: &[String]) -> Vec<String> {
    // FLAGGED: map with a closure that only clones or dereferences
    source.iter().map(|s| s.clone()).collect()
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved