]> git.proxmox.com Git - rustc.git/blame_incremental - src/tools/clippy/tests/ui/iter_nth_zero.rs
bump version to 1.80.1+dfsg1-1~bpo12+pve1
[rustc.git] / src / tools / clippy / tests / ui / iter_nth_zero.rs
... / ...
CommitLineData
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().nth(0);
19
20 let mut s2 = HashSet::new();
21 s2.insert(2);
22 let mut iter = s2.iter();
23 let _y = iter.nth(0);
24
25 let mut s3 = HashSet::new();
26 s3.insert(3);
27 let mut iter2 = s3.iter();
28 let _unwrapped = iter2.nth(0).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}