]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/search_is_some.rs
Auto merge of #87686 - matthiaskrgr:clippy_august_21_perf, r=jackh726
[rust.git] / src / tools / clippy / tests / ui / search_is_some.rs
1 // aux-build:option_helpers.rs
2 #![warn(clippy::search_is_some)]
3 #![allow(dead_code)]
4 extern crate option_helpers;
5 use option_helpers::IteratorFalsePositives;
6
7 #[rustfmt::skip]
8 fn main() {
9     let v = vec![3, 2, 1, 0, -1, -2, -3];
10     let y = &&42;
11
12
13     // Check `find().is_some()`, multi-line case.
14     let _ = v.iter().find(|&x| {
15                               *x < 0
16                           }
17                    ).is_some();
18
19     // Check `position().is_some()`, multi-line case.
20     let _ = v.iter().position(|&x| {
21                                   x < 0
22                               }
23                    ).is_some();
24
25     // Check `rposition().is_some()`, multi-line case.
26     let _ = v.iter().rposition(|&x| {
27                                    x < 0
28                                }
29                    ).is_some();
30
31     // Check that we don't lint if the caller is not an `Iterator` or string
32     let falsepos = IteratorFalsePositives { foo: 0 };
33     let _ = falsepos.find().is_some();
34     let _ = falsepos.position().is_some();
35     let _ = falsepos.rposition().is_some();
36     // check that we don't lint if `find()` is called with
37     // `Pattern` that is not a string
38     let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
39 }
40
41 #[rustfmt::skip]
42 fn is_none() {
43     let v = vec![3, 2, 1, 0, -1, -2, -3];
44     let y = &&42;
45
46
47     // Check `find().is_none()`, multi-line case.
48     let _ = v.iter().find(|&x| {
49                               *x < 0
50                           }
51                    ).is_none();
52
53     // Check `position().is_none()`, multi-line case.
54     let _ = v.iter().position(|&x| {
55                                   x < 0
56                               }
57                    ).is_none();
58
59     // Check `rposition().is_none()`, multi-line case.
60     let _ = v.iter().rposition(|&x| {
61                                    x < 0
62                                }
63                    ).is_none();
64
65     // Check that we don't lint if the caller is not an `Iterator` or string
66     let falsepos = IteratorFalsePositives { foo: 0 };
67     let _ = falsepos.find().is_none();
68     let _ = falsepos.position().is_none();
69     let _ = falsepos.rposition().is_none();
70     // check that we don't lint if `find()` is called with
71     // `Pattern` that is not a string
72     let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none();
73 }