RS.CLIPPY.NEEDLESS_COLLECT
Collecting an iterator when collect is not needed
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_collect. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for functions collecting an iterator when collect is not needed.
Why is this bad?
collect causes the allocation of a new data structure,
when this allocation may not be needed.
Example
let len = iterator.collect::<Vec<_>>().len();
Use instead:
let len = iterator.count();