3 #![warn(clippy::search_is_some)]
6 let v = vec![3, 2, 1, 0, -1, -2, -3];
9 // Check `find().is_none()`, single-line case.
10 let _ = v.iter().find(|&x| *x < 0).is_none();
11 let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less
12 let _ = (0..1).find(|x| *x == 0).is_none();
13 let _ = v.iter().find(|x| **x == 0).is_none();
14 let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none();
15 let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none();
16 let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none();
17 let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none();
19 .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
22 // Check `position().is_none()`, single-line case.
23 let _ = v.iter().position(|&x| x < 0).is_none();
25 // Check `rposition().is_none()`, single-line case.
26 let _ = v.iter().rposition(|&x| x < 0).is_none();
28 let s1 = String::from("hello world");
29 let s2 = String::from("world");
31 // caller of `find()` is a `&`static str`
32 let _ = "hello world".find("world").is_none();
33 let _ = "hello world".find(&s2).is_none();
34 let _ = "hello world".find(&s2[2..]).is_none();
35 // caller of `find()` is a `String`
36 let _ = s1.find("world").is_none();
37 let _ = s1.find(&s2).is_none();
38 let _ = s1.find(&s2[2..]).is_none();
39 // caller of `find()` is slice of `String`
40 let _ = s1[2..].find("world").is_none();
41 let _ = s1[2..].find(&s2).is_none();
42 let _ = s1[2..].find(&s2[2..]).is_none();
45 #[allow(clippy::clone_on_copy, clippy::map_clone)]
52 hand: vec![1, 2, 3, 4, 5],
54 let filter_hand = vec![5];
58 .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none())
64 hand: Vec<(usize, char)>,
68 hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
70 let filter_hand = vec![5];
74 .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none())
79 fn field_projection() {
84 let vfoo = vec![Foo { foo: 1, bar: 2 }];
85 let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none();
87 let vfoo = vec![(42, Foo { foo: 1, bar: 2 })];
90 .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)
94 fn index_projection() {
95 let vfoo = vec![[0, 1, 2, 3]];
96 let _ = vfoo.iter().find(|a| a[0] == 42).is_none();
99 #[allow(clippy::match_like_matches_macro)]
100 fn slice_projection() {
101 let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]];
102 let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none();
105 fn please(x: &u32) -> bool {
109 fn deref_enough(x: u32) -> bool {
113 fn arg_no_deref(x: &&u32) -> bool {
117 fn more_projections() {
120 let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none();
121 let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none();
123 let v = vec![3, 2, 1, 0];
124 let _ = v.iter().find(|x| deref_enough(**x)).is_none();
126 #[allow(clippy::redundant_closure)]
127 let _ = v.iter().find(|x| arg_no_deref(x)).is_none();
130 fn field_index_projection() {
139 inner_double: FooDouble,
141 let vfoo = vec![FooOuter {
142 inner: Foo { bar: vec![0, 1, 2, 3] },
143 inner_double: FooDouble {
144 bar: vec![vec![0, 1, 2, 3]],
149 .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)
153 fn index_field_projection() {
160 let vfoo = vec![FooOuter {
161 inner: vec![Foo { bar: 0 }],
163 let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none();
166 fn double_deref_index_projection() {
167 let vfoo = vec![&&[0, 1, 2, 3]];
168 let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none();