]> git.lizzy.rs Git - rust.git/blob - tests/ui/iter_skip_next.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / iter_skip_next.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
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.
9
10 #![warn(clippy::iter_skip_next)]
11 #![allow(clippy::blacklisted_name)]
12
13 /// Struct to generate false positive for Iterator-based lints
14 #[derive(Copy, Clone)]
15 struct IteratorFalsePositives {
16     foo: u32,
17 }
18
19 impl IteratorFalsePositives {
20     fn filter(self) -> IteratorFalsePositives {
21         self
22     }
23
24     fn next(self) -> IteratorFalsePositives {
25         self
26     }
27
28     fn find(self) -> Option<u32> {
29         Some(self.foo)
30     }
31
32     fn position(self) -> Option<u32> {
33         Some(self.foo)
34     }
35
36     fn rposition(self) -> Option<u32> {
37         Some(self.foo)
38     }
39
40     fn nth(self, n: usize) -> Option<u32> {
41         Some(self.foo)
42     }
43
44     fn skip(self, _: usize) -> IteratorFalsePositives {
45         self
46     }
47 }
48
49 /// Checks implementation of `ITER_SKIP_NEXT` lint
50 fn iter_skip_next() {
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();
59 }
60
61 fn main() {}