RS.CLIPPY.ITER_WITHOUT_INTO_ITER

Implementing `iter(_mut)` without an associated `IntoIterator for (&|&mut) Type` impl

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

What it does

Looks for iter and iter_mut methods without an associated IntoIterator for (&|&mut) Type implementation.

Why is this bad?

It's not bad, but having them is idiomatic and allows the type to be used in for loops directly (for val in &iter {}), without having to first call iter() or iter_mut().

Limitations

This lint focuses on providing an idiomatic API. Therefore, it will only lint on types which are accessible outside of the crate. For internal types, the IntoIterator trait can be implemented on demand if it is actually needed.

Example

struct MySlice<\'a>(&\'a [u8]);
impl<\'a> MySlice<\'a> {
    pub fn iter(&self) -> std::slice::Iter<\'a, u8> {
        self.0.iter()
    }
}

Use instead:

struct MySlice<\'a>(&\'a [u8]);
impl<\'a> MySlice<\'a> {
    pub fn iter(&self) -> std::slice::Iter<\'a, u8> {
        self.0.iter()
    }
}
impl<\'a> IntoIterator for &MySlice<\'a> {
    type Item = &\'a u8;
    type IntoIter = std::slice::Iter<\'a, u8>;
    fn into_iter(self) -> Self::IntoIter {
        self.iter()
    }
}