From f6f16fcd9c5280b5b5a885e3051610fabc166f0c Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:31:44 -0700 Subject: [PATCH] clippy: add `needless_for_each` clippy lint (#10555) Co-authored-by: Oliver --- Cargo.toml | 1 + crates/net/network/tests/it/txgossip.rs | 4 ++-- crates/stages/stages/src/stages/index_account_history.rs | 4 ++-- crates/stages/stages/src/stages/index_storage_history.rs | 4 ++-- crates/static-file/static-file/src/static_file_producer.rs | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acfa6e4a4d..6d54c592ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -220,6 +220,7 @@ zero_sized_map_values = "warn" implicit_clone = "warn" cloned_instead_of_copied = "warn" option_as_ref_cloned = "warn" +needless_for_each = "warn" manual_is_variant_and = "warn" # These are nursery lints which have findings. Allow them for now. Some are not diff --git a/crates/net/network/tests/it/txgossip.rs b/crates/net/network/tests/it/txgossip.rs index d38dea0b02..0467f10fe4 100644 --- a/crates/net/network/tests/it/txgossip.rs +++ b/crates/net/network/tests/it/txgossip.rs @@ -72,10 +72,10 @@ async fn test_4844_tx_gossip_penalization() { // peer 0 will be penalised for sending txs[0] over gossip let txs = vec![gen.gen_eip4844_pooled(), gen.gen_eip1559_pooled()]; - txs.iter().for_each(|tx| { + for tx in &txs { let sender = tx.sender(); provider.add_account(sender, ExtendedAccount::new(0, U256::from(100_000_000))); - }); + } let signed_txs: Vec> = txs.iter().map(|tx| Arc::new(tx.transaction().clone().into_signed())).collect(); diff --git a/crates/stages/stages/src/stages/index_account_history.rs b/crates/stages/stages/src/stages/index_account_history.rs index f3f888a567..6674f81e99 100644 --- a/crates/stages/stages/src/stages/index_account_history.rs +++ b/crates/stages/stages/src/stages/index_account_history.rs @@ -598,7 +598,7 @@ mod tests { .collect::>>(); let last_chunk = chunks.pop(); - chunks.into_iter().for_each(|list| { + for list in chunks { result.insert( ShardedKey::new( address, @@ -607,7 +607,7 @@ mod tests { ), list, ); - }); + } if let Some(last_list) = last_chunk { result.insert(ShardedKey::new(address, u64::MAX), last_list); diff --git a/crates/stages/stages/src/stages/index_storage_history.rs b/crates/stages/stages/src/stages/index_storage_history.rs index 5f2aa0f06d..167fcb4a66 100644 --- a/crates/stages/stages/src/stages/index_storage_history.rs +++ b/crates/stages/stages/src/stages/index_storage_history.rs @@ -624,7 +624,7 @@ mod tests { .collect::>>(); let last_chunk = chunks.pop(); - chunks.into_iter().for_each(|list| { + for list in chunks { result.insert( StorageShardedKey::new( partial_key.0, @@ -634,7 +634,7 @@ mod tests { ), list, ); - }); + } if let Some(last_list) = last_chunk { result.insert( diff --git a/crates/static-file/static-file/src/static_file_producer.rs b/crates/static-file/static-file/src/static_file_producer.rs index f1d41ed1f4..3a18472925 100644 --- a/crates/static-file/static-file/src/static_file_producer.rs +++ b/crates/static-file/static-file/src/static_file_producer.rs @@ -291,10 +291,10 @@ mod tests { static_file_writer.commit().expect("prune headers"); let tx = db.factory.db_ref().tx_mut().expect("init tx"); - blocks.iter().for_each(|block| { + for block in &blocks { TestStageDB::insert_header(None, &tx, &block.header, U256::ZERO) .expect("insert block header"); - }); + } tx.commit().expect("commit tx"); let mut receipts = Vec::new();