RS.CLIPPY.MAP_CLONE

Using `iterator.map(|x| x.clone())`, or dereferencing closures for `Copy` types

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: map_clone. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of map(|x| x.clone()) or dereferencing closures for Copy types, on Iterator or Option, and suggests cloned() or copied() instead

Why is this bad?

Readability, this can be written more concisely

Example

let x = vec![42, 43];
let y = x.iter();
let z = y.map(|i| *i);

The correct use would be:

let x = vec![42, 43];
let y = x.iter();
let z = y.cloned();

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)