2023-04-23 11:03:09 +00:00
|
|
|
//@run-rustfix
|
2019-12-28 22:37:23 +00:00
|
|
|
|
|
|
|
#![warn(clippy::iter_nth_zero)]
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
2022-04-07 17:39:59 +00:00
|
|
|
struct Foo;
|
2019-12-28 22:37:23 +00:00
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn nth(&self, index: usize) -> usize {
|
|
|
|
index + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let f = Foo {};
|
|
|
|
f.nth(0); // lint does not apply here
|
|
|
|
|
|
|
|
let mut s = HashSet::new();
|
|
|
|
s.insert(1);
|
|
|
|
let _x = s.iter().next();
|
|
|
|
|
|
|
|
let mut s2 = HashSet::new();
|
|
|
|
s2.insert(2);
|
|
|
|
let mut iter = s2.iter();
|
|
|
|
let _y = iter.next();
|
|
|
|
|
|
|
|
let mut s3 = HashSet::new();
|
|
|
|
s3.insert(3);
|
|
|
|
let mut iter2 = s3.iter();
|
|
|
|
let _unwrapped = iter2.next().unwrap();
|
|
|
|
}
|
2023-07-02 12:35:19 +00:00
|
|
|
|
|
|
|
struct Issue9820;
|
|
|
|
|
|
|
|
impl Iterator for Issue9820 {
|
|
|
|
type Item = ();
|
|
|
|
|
|
|
|
fn nth(&mut self, _n: usize) -> Option<Self::Item> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't lint in implementations of `next`, as calling `next` in `next` is incorrect
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
self.nth(0)
|
|
|
|
}
|
|
|
|
}
|