summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/iter_skip_next.fixed
blob: d56d623b5268e9a06b15495e58e6ca47924ce9d5 (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
32
33
34
35
36
37
// run-rustfix
// aux-build:option_helpers.rs

#![warn(clippy::iter_skip_next)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::iter_nth)]
#![allow(unused_mut, dead_code)]

extern crate option_helpers;

use option_helpers::IteratorFalsePositives;

/// Checks implementation of `ITER_SKIP_NEXT` lint
fn main() {
    let some_vec = vec![0, 1, 2, 3];
    let _ = some_vec.iter().nth(42);
    let _ = some_vec.iter().cycle().nth(42);
    let _ = (1..10).nth(10);
    let _ = &some_vec[..].iter().nth(3);
    let foo = IteratorFalsePositives { foo: 0 };
    let _ = foo.skip(42).next();
    let _ = foo.filter().skip(42).next();

    // fix #8128
    let test_string = "1|1 2";
    let mut sp = test_string.split('|').map(|s| s.trim());
    let _: Vec<&str> = sp.nth(1).unwrap().split(' ').collect();
    if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) {
        let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect();
    };
    fn check<T>(mut s: T)
    where
        T: Iterator<Item = String>,
    {
        let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect();
    }
}