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().any(|x| *x < 0);
11 let _ = !(0..1).any(|x| **y == x); // one dereference less
12 let _ = !(0..1).any(|x| x == 0);
13 let _ = !v.iter().any(|x| *x == 0);
14 let _ = !(4..5).any(|x| x == 1 || x == 3 || x == 5);
15 let _ = !(1..3).any(|x| [1, 2, 3].contains(&x));
16 let _ = !(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x));
17 let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0);
18 let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1);
20 // Check `position().is_none()`, single-line case.
21 let _ = !v.iter().any(|&x| x < 0);
23 // Check `rposition().is_none()`, single-line case.
24 let _ = !v.iter().any(|&x| x < 0);
26 let s1 = String::from("hello world");
27 let s2 = String::from("world");
29 // caller of `find()` is a `&`static str`
30 let _ = !"hello world".contains("world");
31 let _ = !"hello world".contains(&s2);
32 let _ = !"hello world".contains(&s2[2..]);
33 // caller of `find()` is a `String`
34 let _ = !s1.contains("world");
35 let _ = !s1.contains(&s2);
36 let _ = !s1.contains(&s2[2..]);
37 // caller of `find()` is slice of `String`
38 let _ = !s1[2..].contains("world");
39 let _ = !s1[2..].contains(&s2);
40 let _ = !s1[2..].contains(&s2[2..]);
43 #[allow(clippy::clone_on_copy, clippy::map_clone)]
50 hand: vec![1, 2, 3, 4, 5],
52 let filter_hand = vec![5];
56 .filter(|c| !filter_hand.iter().any(|cc| c == &cc))
62 hand: Vec<(usize, char)>,
66 hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
68 let filter_hand = vec![5];
72 .filter(|(c, _)| !filter_hand.iter().any(|cc| c == cc))
77 fn field_projection() {
82 let vfoo = vec![Foo { foo: 1, bar: 2 }];
83 let _ = !vfoo.iter().any(|v| v.foo == 1 && v.bar == 2);
85 let vfoo = vec![(42, Foo { foo: 1, bar: 2 })];
87 .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2);
90 fn index_projection() {
91 let vfoo = vec![[0, 1, 2, 3]];
92 let _ = !vfoo.iter().any(|a| a[0] == 42);
95 #[allow(clippy::match_like_matches_macro)]
96 fn slice_projection() {
97 let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]];
98 let _ = !vfoo.iter().any(|sub| sub[1..4].len() == 3);
101 fn please(x: &u32) -> bool {
105 fn deref_enough(x: u32) -> bool {
109 fn arg_no_deref(x: &&u32) -> bool {
113 fn more_projections() {
116 let _ = ![ppx].iter().any(|ppp_x: &&u32| please(ppp_x));
117 let _ = ![String::from("Hey hey")].iter().any(|s| s.len() == 2);
119 let v = vec![3, 2, 1, 0];
120 let _ = !v.iter().any(|x| deref_enough(*x));
121 let _ = !v.iter().any(|x: &u32| deref_enough(*x));
123 #[allow(clippy::redundant_closure)]
124 let _ = !v.iter().any(|x| arg_no_deref(&x));
125 #[allow(clippy::redundant_closure)]
126 let _ = !v.iter().any(|x: &u32| arg_no_deref(&x));
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]],
147 .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2);
150 fn index_field_projection() {
157 let vfoo = vec![FooOuter {
158 inner: vec![Foo { bar: 0 }],
160 let _ = !vfoo.iter().any(|v| v.inner[0].bar == 2);
163 fn double_deref_index_projection() {
164 let vfoo = vec![&&[0, 1, 2, 3]];
165 let _ = !vfoo.iter().any(|x| (**x)[0] == 9);
168 fn method_call_by_ref() {
173 pub fn by_ref(&self, x: &u32) -> bool {
177 let vfoo = vec![Foo { bar: 1 }];
178 let _ = !vfoo.iter().any(|v| v.by_ref(&v.bar));
182 let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y);
183 let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y);
186 fn test_string_1(s: &str) -> bool {
190 fn test_u32_1(s: &u32) -> bool {
194 fn test_u32_2(s: u32) -> bool {
198 fn projection_in_args_test() {
200 let lst = &[String::from("Hello"), String::from("world")];
201 let v: Vec<&[String]> = vec![lst];
202 let _ = !v.iter().any(|s| s[0].is_empty());
203 let _ = !v.iter().any(|s| test_string_1(&s[0]));
206 struct FieldProjection<'a> {
209 let field = 123456789;
210 let instance = FieldProjection { field: &field };
211 let v = vec![instance];
212 let _ = !v.iter().any(|fp| fp.field.is_power_of_two());
213 let _ = !v.iter().any(|fp| test_u32_1(fp.field));
214 let _ = !v.iter().any(|fp| test_u32_2(*fp.field));