RS.CLIPPY.ITER_CLONED_COLLECT

Using `.cloned().collect()` on slice to create a `Vec`

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_cloned_collect. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for the use of .cloned().collect() on slice to create a Vec.

Why is this bad?

.to_vec() is clearer

Example

let s = [1, 2, 3, 4, 5];
let s2: Vec<isize> = s[..].iter().cloned().collect();

The better use would be:

let s = [1, 2, 3, 4, 5];
let s2: Vec<isize> = s.to_vec();