RS.CLIPPY.MAP_IDENTITY
Using iterator.map(|x| x)
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_identity. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for instances of map(f) where f is the identity function.
Why is this bad?
It can be written more concisely without the call to map.
Example
let x = [1, 2, 3];
let y: Vec<_> = x.iter().map(|x| x).map(|x| 2*x).collect();
Use instead:
let x = [1, 2, 3];
let y: Vec<_> = x.iter().map(|x| 2*x).collect();