2 #![warn(clippy::needless_for_each)]
3 #![allow(unused, clippy::needless_return, clippy::match_single_binding)]
5 use std::collections::HashMap;
8 let v: Vec<i32> = Vec::new();
10 v.iter().for_each(|elem| {
13 v.into_iter().for_each(|elem| {
17 [1, 2, 3].iter().for_each(|elem| {
21 let mut hash_map: HashMap<i32, i32> = HashMap::new();
22 hash_map.iter().for_each(|(k, v)| {
25 hash_map.iter_mut().for_each(|(k, v)| {
28 hash_map.keys().for_each(|k| {
31 hash_map.values().for_each(|v| {
35 fn my_vec() -> Vec<i32> {
38 my_vec().iter().for_each(|elem| {
43 fn should_not_lint() {
44 let v: Vec<i32> = Vec::new();
47 // `for_each` argument is not closure.
51 v.iter().for_each(print);
58 fn iter(&self) -> impl Iterator<Item = &i32> {
62 let s = MyStruct { v: Vec::new() };
63 s.iter().for_each(|elem| {
67 // `for_each` follows long iterator chain.
68 v.iter().chain(v.iter()).for_each(|v| {
71 v.as_slice().iter().for_each(|v| {
74 s.v.iter().for_each(|v| {
78 // `return` is used in `Loop` of the closure.
79 v.iter().for_each(|v| {
94 // Previously transformed iterator variable.
96 it.chain(v.iter()).for_each(|elem| {
100 // `for_each` is not directly in a statement.
102 _ => v.iter().for_each(|elem| {
107 // `for_each` is in a let bingind.
108 let _ = v.iter().for_each(|elem| {