//@run-rustfix #![warn(clippy::explicit_into_iter_loop)] fn main() { // Issue #4958 fn _takes_iterator(iterator: &T) where for<'a> &'a T: IntoIterator, { for _ in iterator {} } struct T; impl IntoIterator for &T { type Item = (); type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { unimplemented!() } } let mut t = T; for _ in &t {} let r = &t; for _ in r {} // No suggestion for this. // We'd have to suggest `for _ in *rr {}` which is less clear. let rr = &&t; for _ in rr.into_iter() {} let mr = &mut t; for _ in &*mr {} struct U; impl IntoIterator for &mut U { type Item = (); type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { unimplemented!() } } let mut u = U; for _ in &mut u {} let mr = &mut u; for _ in &mut *mr {} // Issue #6900 struct S; impl S { #[allow(clippy::should_implement_trait)] pub fn into_iter(self) -> I { unimplemented!() } } struct I(T); impl Iterator for I { type Item = T; fn next(&mut self) -> Option { unimplemented!() } } for _ in S.into_iter::() {} }