fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![warn(clippy::iter_nth_zero)] 2use std::collections::HashSet; 3 4struct Foo; 5 6impl Foo { 7 fn nth(&self, index: usize) -> usize { 8 index + 1 9 } 10} 11 12fn main() { 13 let f = Foo {}; 14 f.nth(0); // lint does not apply here 15 16 let mut s = HashSet::new(); 17 s.insert(1); 18 let _x = s.iter().next(); 19 20 let mut s2 = HashSet::new(); 21 s2.insert(2); 22 let mut iter = s2.iter(); 23 let _y = iter.next(); 24 25 let mut s3 = HashSet::new(); 26 s3.insert(3); 27 let mut iter2 = s3.iter(); 28 let _unwrapped = iter2.next().unwrap(); 29} 30 31struct Issue9820; 32 33impl Iterator for Issue9820 { 34 type Item = (); 35 36 fn nth(&mut self, _n: usize) -> Option<Self::Item> { 37 todo!() 38 } 39 40 // Don't lint in implementations of `next`, as calling `next` in `next` is incorrect 41 fn next(&mut self) -> Option<Self::Item> { 42 self.nth(0) 43 } 44}