]> git.lizzy.rs Git - rust.git/blob - tests/ui/search_is_some.rs
Move MSRV tests into the lint specific test files
[rust.git] / 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     let some_closure = |x: &u32| *x == 0;
41     let _ = (0..1).find(some_closure).is_some();
42 }
43
44 #[rustfmt::skip]
45 fn is_none() {
46     let v = vec![3, 2, 1, 0, -1, -2, -3];
47     let y = &&42;
48
49
50     // Check `find().is_none()`, multi-line case.
51     let _ = v.iter().find(|&x| {
52                               *x < 0
53                           }
54                    ).is_none();
55
56     // Check `position().is_none()`, multi-line case.
57     let _ = v.iter().position(|&x| {
58                                   x < 0
59                               }
60                    ).is_none();
61
62     // Check `rposition().is_none()`, multi-line case.
63     let _ = v.iter().rposition(|&x| {
64                                    x < 0
65                                }
66                    ).is_none();
67
68     // Check that we don't lint if the caller is not an `Iterator` or string
69     let falsepos = IteratorFalsePositives { foo: 0 };
70     let _ = falsepos.find().is_none();
71     let _ = falsepos.position().is_none();
72     let _ = falsepos.rposition().is_none();
73     // check that we don't lint if `find()` is called with
74     // `Pattern` that is not a string
75     let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none();
76
77     let some_closure = |x: &u32| *x == 0;
78     let _ = (0..1).find(some_closure).is_none();
79 }