2 #![allow(dead_code, clippy::explicit_auto_deref)]
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();
125 let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none();
127 #[allow(clippy::redundant_closure)]
128 let _ = v.iter().find(|x| arg_no_deref(x)).is_none();
129 #[allow(clippy::redundant_closure)]
130 let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none();
133 fn field_index_projection() {
142 inner_double: FooDouble,
144 let vfoo = vec![FooOuter {
145 inner: Foo { bar: vec![0, 1, 2, 3] },
146 inner_double: FooDouble {
147 bar: vec![vec![0, 1, 2, 3]],
152 .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)
156 fn index_field_projection() {
163 let vfoo = vec![FooOuter {
164 inner: vec![Foo { bar: 0 }],
166 let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none();
169 fn double_deref_index_projection() {
170 let vfoo = vec![&&[0, 1, 2, 3]];
171 let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none();
174 fn method_call_by_ref() {
179 pub fn by_ref(&self, x: &u32) -> bool {
183 let vfoo = vec![Foo { bar: 1 }];
184 let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none();
188 let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none();
189 let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none();
192 fn test_string_1(s: &str) -> bool {
196 fn test_u32_1(s: &u32) -> bool {
200 fn test_u32_2(s: u32) -> bool {
204 fn projection_in_args_test() {
206 let lst = &[String::from("Hello"), String::from("world")];
207 let v: Vec<&[String]> = vec![lst];
208 let _ = v.iter().find(|s| s[0].is_empty()).is_none();
209 let _ = v.iter().find(|s| test_string_1(&s[0])).is_none();
212 struct FieldProjection<'a> {
215 let field = 123456789;
216 let instance = FieldProjection { field: &field };
217 let v = vec![instance];
218 let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none();
219 let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none();
220 let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none();