RS.CLIPPY.ITER_ON_EMPTY_COLLECTIONS
Iterator for empty array
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_on_empty_collections. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for calls to iter, iter_mut or into_iter on empty collections
Why is this bad?
It is simpler to use the empty function from the standard library:
Example
use std::{slice, option};
let a: slice::Iter<i32> = [].iter();
let f: option::IntoIter<i32> = None.into_iter();
Use instead:
use std::iter;
let a: iter::Empty<i32> = iter::empty();
let b: iter::Empty<i32> = iter::empty();
Known problems
The type of the resulting iterator might become incompatible with its usage