2 #![warn(clippy::needless_for_each)]
5 clippy::needless_return,
6 clippy::match_single_binding,
10 use std::collections::HashMap;
13 let v: Vec<i32> = Vec::new();
15 v.iter().for_each(|elem| {
18 v.into_iter().for_each(|elem| {
22 [1, 2, 3].iter().for_each(|elem| {
26 let mut hash_map: HashMap<i32, i32> = HashMap::new();
27 hash_map.iter().for_each(|(k, v)| {
30 hash_map.iter_mut().for_each(|(k, v)| {
33 hash_map.keys().for_each(|k| {
36 hash_map.values().for_each(|v| {
40 fn my_vec() -> Vec<i32> {
43 my_vec().iter().for_each(|elem| {
48 fn should_not_lint() {
49 let v: Vec<i32> = Vec::new();
52 // `for_each` argument is not closure.
56 v.iter().for_each(print);
63 fn iter(&self) -> impl Iterator<Item = &i32> {
67 let s = MyStruct { v: Vec::new() };
68 s.iter().for_each(|elem| {
72 // `for_each` follows long iterator chain.
73 v.iter().chain(v.iter()).for_each(|v| {
76 v.as_slice().iter().for_each(|v| {
79 s.v.iter().for_each(|v| {
83 // `return` is used in `Loop` of the closure.
84 v.iter().for_each(|v| {
99 // Previously transformed iterator variable.
101 it.chain(v.iter()).for_each(|elem| {
105 // `for_each` is not directly in a statement.
107 _ => v.iter().for_each(|elem| {
112 // `for_each` is in a let bingind.
113 let _ = v.iter().for_each(|elem| {