2 #![warn(clippy::manual_find)]
4 #![allow(clippy::needless_return, clippy::uninlined_format_args)]
6 use std::collections::HashMap;
8 const ARRAY: &[u32; 5] = &[2, 7, 1, 9, 3];
10 fn lookup(n: u32) -> Option<u32> {
11 ARRAY.iter().find(|&&v| v == n).copied()
14 fn with_pat(arr: Vec<(u32, u32)>) -> Option<u32> {
15 arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)
22 fn with_struct(arr: Vec<Data>) -> Option<Data> {
23 arr.into_iter().find(|el| el.name.len() == 10)
26 struct Tuple(usize, usize);
27 fn with_tuple_struct(arr: Vec<Tuple>) -> Option<usize> {
28 arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)
33 fn should_keep(&self) -> bool {
37 fn with_method_call(arr: Vec<A>) -> Option<A> {
38 arr.into_iter().find(|el| el.should_keep())
41 fn with_closure(arr: Vec<u32>) -> Option<u32> {
42 let f = |el: u32| -> u32 { el + 10 };
43 arr.into_iter().find(|&el| f(el) == 20)
46 fn with_closure2(arr: HashMap<String, i32>) -> Option<i32> {
47 let f = |el: i32| -> bool { el == 10 };
48 arr.values().find(|&&el| f(el)).copied()
51 fn with_bool(arr: Vec<Data>) -> Option<Data> {
52 arr.into_iter().find(|el| el.is_true)
55 fn with_side_effects(arr: Vec<u32>) -> Option<u32> {
58 println!("side effect");
65 fn with_else(arr: Vec<u32>) -> Option<u32> {
76 fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option<u8> {
77 v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)
80 fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option<u8> {
81 v.iter().map(|&(_, &x)| x).find(|&x| x > 10)
84 fn explicit_ret(arr: Vec<i32>) -> Option<i32> {
85 arr.into_iter().find(|&x| x >= 5)
88 fn plus_one(a: i32) -> Option<i32> {
91 fn fn_instead_of_some(a: &[i32]) -> Option<i32> {
100 fn for_in_condition(a: &[i32], b: bool) -> Option<i32> {
111 fn intermediate_statements(a: &[i32]) -> Option<i32> {
118 println!("side effect");
123 fn mixed_binding_modes(arr: Vec<(i32, String)>) -> Option<i32> {
124 for (x, mut s) in arr {
125 if x == 1 && s.as_mut_str().len() == 2 {
134 let f = |arr: Vec<i32>| -> Option<i32> {
135 arr.into_iter().find(|&x| x < 1)
139 fn in_block(a: &[i32]) -> Option<i32> {
140 let should_be_none = {
149 assert!(should_be_none.is_none());
155 fn mut_binding(v: Vec<String>) -> Option<String> {
157 if s.as_mut_str().len() > 1 {
164 fn subpattern(v: Vec<[u32; 32]>) -> Option<[u32; 32]> {
165 for a @ [first, ..] in v {
173 fn two_bindings(v: Vec<(u8, u8)>) -> Option<u8> {