2023-07-02 07:35:19 -05:00
|
|
|
#![deny(clippy::explicit_iter_loop)]
|
|
|
|
#![allow(
|
|
|
|
clippy::linkedlist,
|
|
|
|
clippy::similar_names,
|
|
|
|
clippy::needless_borrow,
|
|
|
|
clippy::deref_addrof,
|
2023-09-12 11:13:53 -05:00
|
|
|
clippy::unnecessary_mut_passed,
|
2024-01-26 11:48:18 -06:00
|
|
|
dead_code,
|
2024-03-07 10:19:29 -06:00
|
|
|
non_local_definitions
|
2023-07-02 07:35:19 -05:00
|
|
|
)]
|
|
|
|
|
|
|
|
use core::slice;
|
|
|
|
use std::collections::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut vec = vec![1, 2, 3, 4];
|
|
|
|
|
|
|
|
for _ in &vec {}
|
|
|
|
for _ in &mut vec {}
|
|
|
|
|
|
|
|
let rvec = &vec;
|
|
|
|
for _ in rvec {}
|
|
|
|
|
|
|
|
let rmvec = &mut vec;
|
2023-09-12 11:13:53 -05:00
|
|
|
for _ in rmvec.iter() {}
|
|
|
|
for _ in rmvec.iter_mut() {}
|
2023-07-02 07:35:19 -05:00
|
|
|
|
|
|
|
for _ in &vec {} // these are fine
|
|
|
|
for _ in &mut vec {} // these are fine
|
|
|
|
|
|
|
|
for _ in &[1, 2, 3] {}
|
|
|
|
|
2023-09-12 11:13:53 -05:00
|
|
|
for _ in (&mut [1, 2, 3]).iter() {}
|
2023-07-02 07:35:19 -05:00
|
|
|
|
|
|
|
for _ in &[0; 32] {}
|
|
|
|
for _ in &[0; 33] {}
|
|
|
|
|
|
|
|
let ll: LinkedList<()> = LinkedList::new();
|
|
|
|
for _ in &ll {}
|
|
|
|
let rll = ≪
|
|
|
|
for _ in rll {}
|
|
|
|
|
|
|
|
let vd: VecDeque<()> = VecDeque::new();
|
|
|
|
for _ in &vd {}
|
|
|
|
let rvd = &vd;
|
|
|
|
for _ in rvd {}
|
|
|
|
|
|
|
|
let bh: BinaryHeap<()> = BinaryHeap::new();
|
|
|
|
for _ in &bh {}
|
|
|
|
|
|
|
|
let hm: HashMap<(), ()> = HashMap::new();
|
|
|
|
for _ in &hm {}
|
|
|
|
|
|
|
|
let bt: BTreeMap<(), ()> = BTreeMap::new();
|
|
|
|
for _ in &bt {}
|
|
|
|
|
|
|
|
let hs: HashSet<()> = HashSet::new();
|
|
|
|
for _ in &hs {}
|
|
|
|
|
|
|
|
let bs: BTreeSet<()> = BTreeSet::new();
|
|
|
|
for _ in &bs {}
|
|
|
|
|
|
|
|
struct NoIntoIter();
|
|
|
|
impl NoIntoIter {
|
|
|
|
fn iter(&self) -> slice::Iter<u8> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iter_mut(&mut self) -> slice::IterMut<u8> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut x = NoIntoIter();
|
|
|
|
for _ in x.iter() {} // no error
|
|
|
|
for _ in x.iter_mut() {} // no error
|
|
|
|
|
|
|
|
struct IntoIterDiffTy;
|
|
|
|
impl IntoIterator for &'_ IntoIterDiffTy {
|
|
|
|
type Item = &'static ();
|
|
|
|
type IntoIter = core::slice::Iter<'static, ()>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl IntoIterDiffTy {
|
|
|
|
fn iter(&self) -> core::slice::Iter<'static, i32> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let x = IntoIterDiffTy;
|
|
|
|
for _ in x.iter() {}
|
|
|
|
|
|
|
|
struct IntoIterDiffSig;
|
|
|
|
impl IntoIterator for &'_ IntoIterDiffSig {
|
|
|
|
type Item = &'static ();
|
|
|
|
type IntoIter = core::slice::Iter<'static, ()>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl IntoIterDiffSig {
|
|
|
|
fn iter(&self, _: u32) -> core::slice::Iter<'static, ()> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let x = IntoIterDiffSig;
|
|
|
|
for _ in x.iter(0) {}
|
|
|
|
|
|
|
|
struct IntoIterDiffLt<'a>(&'a ());
|
|
|
|
impl<'a> IntoIterator for &'a IntoIterDiffLt<'_> {
|
|
|
|
type Item = &'a ();
|
|
|
|
type IntoIter = core::slice::Iter<'a, ()>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> IntoIterDiffLt<'a> {
|
|
|
|
fn iter(&self) -> core::slice::Iter<'a, ()> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let x = IntoIterDiffLt(&());
|
|
|
|
for _ in x.iter() {}
|
|
|
|
|
|
|
|
struct CustomType;
|
|
|
|
impl<'a> IntoIterator for &'a CustomType {
|
|
|
|
type Item = &'a u32;
|
|
|
|
type IntoIter = core::slice::Iter<'a, u32>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> IntoIterator for &'a mut CustomType {
|
|
|
|
type Item = &'a mut u32;
|
|
|
|
type IntoIter = core::slice::IterMut<'a, u32>;
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl CustomType {
|
|
|
|
fn iter(&self) -> <&'_ Self as IntoIterator>::IntoIter {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn iter_mut(&mut self) -> core::slice::IterMut<'_, u32> {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut x = CustomType;
|
|
|
|
for _ in &x {}
|
|
|
|
for _ in &mut x {}
|
|
|
|
|
|
|
|
let r = &x;
|
|
|
|
for _ in r {}
|
|
|
|
}
|