]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/auxiliary/option_helpers.rs
Rollup merge of #104517 - dfordivam:patch-1, r=cuviper
[rust.git] / src / tools / clippy / tests / ui / auxiliary / option_helpers.rs
1 #![allow(dead_code, unused_variables, clippy::return_self_not_must_use)]
2
3 /// Utility macro to test linting behavior in `option_methods()`
4 /// The lints included in `option_methods()` should not lint if the call to map is partially
5 /// within a macro
6 #[macro_export]
7 macro_rules! opt_map {
8     ($opt:expr, $map:expr) => {
9         ($opt).map($map)
10     };
11 }
12
13 /// Struct to generate false positive for Iterator-based lints
14 #[derive(Copy, Clone)]
15 pub struct IteratorFalsePositives {
16     pub foo: u32,
17 }
18
19 impl IteratorFalsePositives {
20     pub fn filter(self) -> IteratorFalsePositives {
21         self
22     }
23
24     pub fn next(self) -> IteratorFalsePositives {
25         self
26     }
27
28     pub fn find(self) -> Option<u32> {
29         Some(self.foo)
30     }
31
32     pub fn position(self) -> Option<u32> {
33         Some(self.foo)
34     }
35
36     pub fn rposition(self) -> Option<u32> {
37         Some(self.foo)
38     }
39
40     pub fn nth(self, n: usize) -> Option<u32> {
41         Some(self.foo)
42     }
43
44     pub fn skip(self, _: usize) -> IteratorFalsePositives {
45         self
46     }
47
48     pub fn skip_while(self) -> IteratorFalsePositives {
49         self
50     }
51
52     pub fn count(self) -> usize {
53         self.foo as usize
54     }
55 }
56
57 #[derive(Copy, Clone)]
58 pub struct IteratorMethodFalsePositives;
59
60 impl IteratorMethodFalsePositives {
61     pub fn filter(&self, _s: i32) -> std::vec::IntoIter<i32> {
62         unimplemented!();
63     }
64 }