RS.CLIPPY.COLLECTION_IS_NEVER_READ

A collection is never queried

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

What it does

Checks for collections that are never queried.

Why is this bad?

Putting effort into constructing a collection but then never querying it might indicate that the author forgot to do whatever they intended to do with the collection. Example: Clone a vector, sort it for iteration, but then mistakenly iterate the original vector instead.

Example

let mut sorted_samples = samples.clone();
sorted_samples.sort();
for sample in &samples { // Oops, meant to use `sorted_samples`.
    println!("{sample}");
}

Use instead:

let mut sorted_samples = samples.clone();
sorted_samples.sort();
for sample in &sorted_samples {
    println!("{sample}");
}