RS.CLIPPY.SINGLE_ELEMENT_LOOP
There is no reason to have a single element loop
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: single_element_loop. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks whether a for loop has a single element.
Why is this bad?
There is no reason to have a loop of a single element.
Example
let item1 = 2;
for item in &[item1] {
println!("{}", item);
}
Use instead:
let item1 = 2;
let item = &item1;
println!("{}", item);