3 #![warn(clippy::search_is_some)]
6 let v = vec![3, 2, 1, 0, -1, -2, -3];
9 // Check `find().is_some()`, single-line case.
10 let _ = v.iter().find(|&x| *x < 0).is_some();
11 let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
12 let _ = (0..1).find(|x| *x == 0).is_some();
13 let _ = v.iter().find(|x| **x == 0).is_some();
14 let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some();
15 let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some();
16 let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some();
17 let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some();
19 .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
22 // Check `position().is_some()`, single-line case.
23 let _ = v.iter().position(|&x| x < 0).is_some();
25 // Check `rposition().is_some()`, single-line case.
26 let _ = v.iter().rposition(|&x| x < 0).is_some();
28 let s1 = String::from("hello world");
29 let s2 = String::from("world");
30 // caller of `find()` is a `&`static str`
31 let _ = "hello world".find("world").is_some();
32 let _ = "hello world".find(&s2).is_some();
33 let _ = "hello world".find(&s2[2..]).is_some();
34 // caller of `find()` is a `String`
35 let _ = s1.find("world").is_some();
36 let _ = s1.find(&s2).is_some();
37 let _ = s1.find(&s2[2..]).is_some();
38 // caller of `find()` is slice of `String`
39 let _ = s1[2..].find("world").is_some();
40 let _ = s1[2..].find(&s2).is_some();
41 let _ = s1[2..].find(&s2[2..]).is_some();
44 #[allow(clippy::clone_on_copy, clippy::map_clone)]
51 hand: vec![1, 2, 3, 4, 5],
53 let filter_hand = vec![5];
57 .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some())
63 hand: Vec<(usize, char)>,
67 hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
69 let filter_hand = vec![5];
73 .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some())
78 fn field_projection() {
83 let vfoo = vec![Foo { foo: 1, bar: 2 }];
84 let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some();
86 let vfoo = vec![(42, Foo { foo: 1, bar: 2 })];
89 .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)
93 fn index_projection() {
94 let vfoo = vec![[0, 1, 2, 3]];
95 let _ = vfoo.iter().find(|a| a[0] == 42).is_some();
98 #[allow(clippy::match_like_matches_macro)]
99 fn slice_projection() {
100 let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]];
101 let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some();
104 fn please(x: &u32) -> bool {
108 fn deref_enough(x: u32) -> bool {
112 fn arg_no_deref(x: &&u32) -> bool {
116 fn more_projections() {
119 let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some();
120 let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some();
122 let v = vec![3, 2, 1, 0];
123 let _ = v.iter().find(|x| deref_enough(**x)).is_some();
125 #[allow(clippy::redundant_closure)]
126 let _ = v.iter().find(|x| arg_no_deref(x)).is_some();
129 fn field_index_projection() {
138 inner_double: FooDouble,
140 let vfoo = vec![FooOuter {
141 inner: Foo { bar: vec![0, 1, 2, 3] },
142 inner_double: FooDouble {
143 bar: vec![vec![0, 1, 2, 3]],
148 .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)
152 fn index_field_projection() {
159 let vfoo = vec![FooOuter {
160 inner: vec![Foo { bar: 0 }],
162 let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some();
165 fn double_deref_index_projection() {
166 let vfoo = vec![&&[0, 1, 2, 3]];
167 let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some();
170 fn method_call_by_ref() {
175 pub fn by_ref(&self, x: &u32) -> bool {
179 let vfoo = vec![Foo { bar: 1 }];
180 let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some();