RS.CLIPPY.ITER_OVEREAGER_CLONED
Using `cloned()` early with `Iterator::iter()` can lead to some performance inefficiencies
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: iter_overeager_cloned. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of _.cloned().<func>() where call to .cloned() can be postponed.
Why is this bad?
It's often inefficient to clone all elements of an iterator, when eventually, only some of them will be consumed.
Known Problems
This lint removes the side of effect of cloning items in the iterator.
A code that relies on that side-effect could fail.
Examples
vec.iter().cloned().take(10);
vec.iter().cloned().last();
Use instead:
vec.iter().take(10).cloned();
vec.iter().last().cloned();