summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/iter_nth_zero.rs
blob: 7c968d49845714574db74baaf2178eff36244467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// run-rustfix

#![warn(clippy::iter_nth_zero)]
use std::collections::HashSet;

struct Foo;

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().nth(0);

    let mut s2 = HashSet::new();
    s2.insert(2);
    let mut iter = s2.iter();
    let _y = iter.nth(0);

    let mut s3 = HashSet::new();
    s3.insert(3);
    let mut iter2 = s3.iter();
    let _unwrapped = iter2.nth(0).unwrap();
}