1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::iter_skip_next)]
11 #![allow(clippy::blacklisted_name)]
13 /// Struct to generate false positive for Iterator-based lints
14 #[derive(Copy, Clone)]
15 struct IteratorFalsePositives {
19 impl IteratorFalsePositives {
20 fn filter(self) -> IteratorFalsePositives {
24 fn next(self) -> IteratorFalsePositives {
28 fn find(self) -> Option<u32> {
32 fn position(self) -> Option<u32> {
36 fn rposition(self) -> Option<u32> {
40 fn nth(self, n: usize) -> Option<u32> {
44 fn skip(self, _: usize) -> IteratorFalsePositives {
49 /// Checks implementation of `ITER_SKIP_NEXT` lint
51 let mut some_vec = vec![0, 1, 2, 3];
52 let _ = some_vec.iter().skip(42).next();
53 let _ = some_vec.iter().cycle().skip(42).next();
54 let _ = (1..10).skip(10).next();
55 let _ = &some_vec[..].iter().skip(3).next();
56 let foo = IteratorFalsePositives { foo: 0 };
57 let _ = foo.skip(42).next();
58 let _ = foo.filter().skip(42).next();