Skip to content

Commit 44c4416

Browse files
authored
feat: add explicit_iter_loop clippy lint (#10146)
1 parent 8c66f68 commit 44c4416

File tree

37 files changed

+59
-58
lines changed

37 files changed

+59
-58
lines changed

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exclude = ["benches/", "tests/", "test-data/", "testdata/"]
3939

4040
[workspace.lints.clippy]
4141
dbg-macro = "warn"
42+
explicit_iter_loop = "warn"
4243
manual-string-new = "warn"
4344
uninlined-format-args = "warn"
4445
use-self = "warn"

Diff for: crates/anvil/src/eth/backend/genesis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl GenesisConfig {
5050
// insert all accounts
5151
db.insert_account(addr, self.genesis_to_account_info(&acc));
5252
// insert all storage values
53-
for (k, v) in storage.unwrap_or_default().iter() {
53+
for (k, v) in &storage.unwrap_or_default() {
5454
db.set_storage_at(addr, *k, *v)?;
5555
}
5656
}

Diff for: crates/anvil/src/eth/backend/mem/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979
D: DatabaseRef<Error = DatabaseError>,
8080
{
8181
let mut cache_db = CacheDB::new(state);
82-
for (account, account_overrides) in overrides.iter() {
82+
for (account, account_overrides) in &overrides {
8383
let mut account_info = cache_db.basic_ref(*account)?.unwrap_or_default();
8484

8585
if let Some(nonce) = account_overrides.nonce {
@@ -114,7 +114,7 @@ where
114114
)?;
115115
}
116116
(None, Some(account_state_diff)) => {
117-
for (key, value) in account_state_diff.iter() {
117+
for (key, value) in account_state_diff {
118118
cache_db.insert_account_storage(*account, (*key).into(), (*value).into())?;
119119
}
120120
}

Diff for: crates/anvil/src/eth/backend/mem/storage.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl BlockchainStorage {
373373
/// Removes all stored transactions for the given block hash
374374
pub fn remove_block_transactions(&mut self, block_hash: B256) {
375375
if let Some(block) = self.blocks.get_mut(&block_hash) {
376-
for tx in block.transactions.iter() {
376+
for tx in &block.transactions {
377377
self.transactions.remove(&tx.hash());
378378
}
379379
block.transactions.clear();
@@ -419,7 +419,7 @@ impl BlockchainStorage {
419419

420420
/// Deserialize and add all blocks data to the backend storage
421421
pub fn load_blocks(&mut self, serializable_blocks: Vec<SerializableBlock>) {
422-
for serializable_block in serializable_blocks.iter() {
422+
for serializable_block in &serializable_blocks {
423423
let block: Block = serializable_block.clone().into();
424424
let block_hash = block.header.hash_slow();
425425
let block_number = block.header.number;
@@ -430,7 +430,7 @@ impl BlockchainStorage {
430430

431431
/// Deserialize and add all blocks data to the backend storage
432432
pub fn load_transactions(&mut self, serializable_transactions: Vec<SerializableTransaction>) {
433-
for serializable_transaction in serializable_transactions.iter() {
433+
for serializable_transaction in &serializable_transactions {
434434
let transaction: MinedTransaction = serializable_transaction.clone().into();
435435
self.transactions.insert(transaction.info.transaction_hash, transaction);
436436
}

Diff for: crates/anvil/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl Future for NodeHandle {
434434
}
435435

436436
// poll the axum server handles
437-
for server in pin.servers.iter_mut() {
437+
for server in &mut pin.servers {
438438
if let Poll::Ready(res) = server.poll_unpin(cx) {
439439
return Poll::Ready(res);
440440
}

Diff for: crates/cheatcodes/src/evm/record_debug_step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn recursive_flatten_call_trace<'a>(
4141

4242
let node = &arena.nodes()[node_idx];
4343

44-
for order in node.ordering.iter() {
44+
for order in &node.ordering {
4545
match order {
4646
TraceMemberOrder::Step(step_idx) => {
4747
if *record_started {

Diff for: crates/cli/src/opts/dependency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl FromStr for Dependency {
6565
let mut dependency = dependency.to_string();
6666
// this will autocorrect wrong conventional aliases for tag, but only autocorrect if
6767
// it's not used as alias
68-
for (alias, real_org) in COMMON_ORG_ALIASES.iter() {
68+
for (alias, real_org) in COMMON_ORG_ALIASES {
6969
if dependency.starts_with(alias) {
7070
dependency = dependency.replacen(alias, real_org, 1);
7171
break

Diff for: crates/cli/src/utils/cmd.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ pub fn get_cached_entry_by_name(
8080
let mut cached_entry = None;
8181
let mut alternatives = Vec::new();
8282

83-
for (abs_path, entry) in cache.files.iter() {
84-
for (artifact_name, _) in entry.artifacts.iter() {
83+
for (abs_path, entry) in &cache.files {
84+
for artifact_name in entry.artifacts.keys() {
8585
if artifact_name == name {
8686
if cached_entry.is_some() {
8787
eyre::bail!(
@@ -124,7 +124,7 @@ pub fn ensure_clean_constructor(abi: &JsonAbi) -> Result<()> {
124124
pub fn needs_setup(abi: &JsonAbi) -> bool {
125125
let setup_fns: Vec<_> = abi.functions().filter(|func| func.name.is_setup()).collect();
126126

127-
for setup_fn in setup_fns.iter() {
127+
for setup_fn in &setup_fns {
128128
if setup_fn.name != "setUp" {
129129
let _ = sh_warn!(
130130
"Found invalid setup function \"{}\" did you mean \"setUp()\"?",

Diff for: crates/common/fmt/src/ui.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl UIfmt for OtherFields {
291291
if !self.is_empty() {
292292
s.push('\n');
293293
}
294-
for (key, value) in self.iter() {
294+
for (key, value) in self {
295295
let val = EthValue::from(value.clone()).pretty();
296296
let offset = NAME_COLUMN_LEN.saturating_sub(key.len());
297297
s.push_str(key);

Diff for: crates/common/src/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub fn etherscan_project(
507507
let mut settings = metadata.settings()?;
508508

509509
// make remappings absolute with our root
510-
for remapping in settings.remappings.iter_mut() {
510+
for remapping in &mut settings.remappings {
511511
let new_path = sources_path.join(remapping.path.trim_start_matches('/'));
512512
remapping.path = new_path.display().to_string();
513513
}

Diff for: crates/common/src/provider/runtime_transport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl RuntimeTransport {
165165
};
166166

167167
// Add any custom headers.
168-
for header in self.headers.iter() {
168+
for header in &self.headers {
169169
let make_err = || RuntimeTransportError::BadHeader(header.to_string());
170170

171171
let (key, val) = header.split_once(':').ok_or_else(make_err)?;

Diff for: crates/config/src/inline/natspec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl SolcParser {
123123
/// Given a list of nodes, find a "ContractDefinition" node that matches
124124
/// the provided contract_id.
125125
fn contract_root_node<'a>(&self, nodes: &'a [Node], contract_id: &str) -> Option<&'a Node> {
126-
for n in nodes.iter() {
126+
for n in nodes {
127127
if n.node_type == NodeType::ContractDefinition {
128128
let contract_data = &n.other;
129129
if let Value::String(contract_name) = contract_data.get("name")? {
@@ -145,7 +145,7 @@ impl SolcParser {
145145
natspecs.push(NatSpec { contract: contract.into(), function: None, docs, line })
146146
}
147147
}
148-
for n in node.nodes.iter() {
148+
for n in &node.nodes {
149149
if let Some((function, docs, line)) = self.get_fn_data(n) {
150150
natspecs.push(NatSpec {
151151
contract: contract.into(),

Diff for: crates/config/src/providers/ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl<P: Provider> Provider for FallbackProfileProvider<P> {
545545
let data = self.provider.data()?;
546546
if let Some(fallback) = data.get(&self.fallback) {
547547
let mut inner = data.get(&self.profile).cloned().unwrap_or_default();
548-
for (k, v) in fallback.iter() {
548+
for (k, v) in fallback {
549549
if !inner.contains_key(k) {
550550
inner.insert(k.to_owned(), v.clone());
551551
}

Diff for: crates/debugger/src/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn flatten_call_trace(arena: CallTraceArena, out: &mut Vec<DebugNode>) {
4444
fn inner(arena: &CallTraceArena, node_idx: usize, out: &mut Vec<PendingNode>) {
4545
let mut pending = PendingNode { node_idx, steps_count: 0 };
4646
let node = &arena.nodes()[node_idx];
47-
for order in node.ordering.iter() {
47+
for order in &node.ordering {
4848
match order {
4949
TraceMemberOrder::Call(idx) => {
5050
out.push(pending);

Diff for: crates/doc/src/parser/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Visitor for Parser {
133133
type Error = ParserError;
134134

135135
fn visit_source_unit(&mut self, source_unit: &mut SourceUnit) -> ParserResult<()> {
136-
for source in source_unit.0.iter_mut() {
136+
for source in &mut source_unit.0 {
137137
match source {
138138
SourceUnitPart::ContractDefinition(def) => {
139139
// Create new contract parse item.
@@ -184,7 +184,7 @@ impl Visitor for Parser {
184184
// If the function parameter doesn't have a name, try to set it with
185185
// `@custom:name` tag if any was provided
186186
let mut start_loc = func.loc.start();
187-
for (loc, param) in func.params.iter_mut() {
187+
for (loc, param) in &mut func.params {
188188
if let Some(param) = param {
189189
if param.name.is_none() {
190190
let docs = self.parse_docs_range(start_loc, loc.end())?;

Diff for: crates/doc/src/preprocessor/contract_inheritance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl Preprocessor for ContractInheritance {
2626
}
2727

2828
fn preprocess(&self, documents: Vec<Document>) -> Result<Vec<Document>, eyre::Error> {
29-
for document in documents.iter() {
29+
for document in &documents {
3030
if let DocumentContent::Single(ref item) = document.content {
3131
if let ParseSource::Contract(ref contract) = item.source {
3232
let mut links = HashMap::default();
3333

3434
// Attempt to match bases to other contracts
35-
for base in contract.base.iter() {
35+
for base in &contract.base {
3636
let base_ident = base.name.identifiers.last().unwrap().name.clone();
3737
if let Some(linked) = self.try_link_base(&base_ident, &documents) {
3838
links.insert(base_ident, linked);

Diff for: crates/doc/src/preprocessor/deployments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Preprocessor for Deployments {
5555
.collect::<Result<Vec<_>, _>>()?;
5656

5757
// Iterate over all documents to find any deployments.
58-
for document in documents.iter() {
58+
for document in &documents {
5959
let mut deployments = Vec::default();
6060

6161
// Iterate over all networks and check if there is a deployment for the given contract.

Diff for: crates/doc/src/preprocessor/git_source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Preprocessor for GitSource {
2727
if let Some(ref repo) = self.repository {
2828
let repo = repo.trim_end_matches('/');
2929
let commit = self.commit.clone().unwrap_or("master".to_owned());
30-
for document in documents.iter() {
30+
for document in &documents {
3131
if document.from_library {
3232
continue;
3333
}

Diff for: crates/doc/src/preprocessor/inheritdoc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Preprocessor for Inheritdoc {
2323
}
2424

2525
fn preprocess(&self, documents: Vec<Document>) -> Result<Vec<Document>, eyre::Error> {
26-
for document in documents.iter() {
26+
for document in &documents {
2727
if let DocumentContent::Single(ref item) = document.content {
2828
let context = self.visit_item(item, &documents);
2929
if !context.is_empty() {
@@ -50,7 +50,7 @@ impl Inheritdoc {
5050
}
5151

5252
// Match item's children.
53-
for ch in item.children.iter() {
53+
for ch in &item.children {
5454
let matched = ch
5555
.comments
5656
.find_inheritdoc_base()
@@ -76,7 +76,7 @@ impl Inheritdoc {
7676
// Not matched for the contract because it's a noop
7777
// https://docs.soliditylang.org/en/v0.8.17/natspec-format.html#tags
7878

79-
for children in item.children.iter() {
79+
for children in &item.children {
8080
// TODO: improve matching logic
8181
if source.ident() == children.source.ident() {
8282
let key = format!("{}.{}", base, source.ident());

Diff for: crates/doc/src/writer/as_doc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl AsDoc for Document {
9696
writer.writeln()?;
9797
}
9898

99-
for item in items.iter() {
99+
for item in items {
100100
let func = item.as_function().unwrap();
101101
let mut heading = item.source.ident();
102102
if !func.params.is_empty() {
@@ -119,7 +119,7 @@ impl AsDoc for Document {
119119
writer.writeln()?;
120120
}
121121

122-
for item in items.iter() {
122+
for item in items {
123123
let var = item.as_variable().unwrap();
124124
writer.write_heading(&var.name.safe_unwrap().name)?;
125125
writer.write_section(&item.comments, &item.code)?;
@@ -147,7 +147,7 @@ impl AsDoc for Document {
147147
let mut bases = vec![];
148148
let linked =
149149
read_context!(self, CONTRACT_INHERITANCE_ID, ContractInheritance);
150-
for base in contract.base.iter() {
150+
for base in &contract.base {
151151
let base_doc = base.as_doc()?;
152152
let base_ident = &base.name.identifiers.last().unwrap().name;
153153

@@ -193,7 +193,7 @@ impl AsDoc for Document {
193193
if let Some(funcs) = item.functions() {
194194
writer.write_subtitle("Functions")?;
195195

196-
for (func, comments, code) in funcs.iter() {
196+
for (func, comments, code) in &funcs {
197197
self.write_function(&mut writer, func, comments, code)?;
198198
}
199199
}

Diff for: crates/evm/core/src/backend/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ impl DatabaseExt for Backend {
11821182
// Special case for accounts that are not created: we don't merge their state but
11831183
// load it in order to reflect their state at the new block (they should explicitly
11841184
// be marked as persistent if it is desired to keep state between fork rolls).
1185-
for (addr, acc) in journaled_state.state.iter() {
1185+
for (addr, acc) in &journaled_state.state {
11861186
if acc.is_created() {
11871187
if acc.is_touched() {
11881188
merge_journaled_state_data(
@@ -1375,7 +1375,7 @@ impl DatabaseExt for Backend {
13751375
journaled_state: &mut JournaledState,
13761376
) -> Result<(), BackendError> {
13771377
// Loop through all of the allocs defined in the map and commit them to the journal.
1378-
for (addr, acc) in allocs.iter() {
1378+
for (addr, acc) in allocs {
13791379
self.clone_account(acc, addr, journaled_state)?;
13801380
}
13811381

@@ -1967,7 +1967,7 @@ pub fn update_state<DB: Database>(
19671967
for (addr, acc) in state.iter_mut() {
19681968
if !persistent_accounts.is_some_and(|accounts| accounts.contains(addr)) {
19691969
acc.info = db.basic(*addr)?.unwrap_or_default();
1970-
for (key, val) in acc.storage.iter_mut() {
1970+
for (key, val) in &mut acc.storage {
19711971
val.present_value = db.storage(*addr, *key)?;
19721972
}
19731973
}

Diff for: crates/evm/core/src/fork/multi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl MultiForkHandler {
256256

257257
/// Returns the list of additional senders of a matching task for the given id, if any.
258258
fn find_in_progress_task(&mut self, id: &ForkId) -> Option<&mut Vec<CreateSender>> {
259-
for task in self.pending_tasks.iter_mut() {
259+
for task in &mut self.pending_tasks {
260260
#[allow(irrefutable_let_patterns)]
261261
if let ForkTask::Create(_, in_progress, _, additional) = task {
262262
if in_progress == id {

Diff for: crates/evm/evm/src/executors/invariant/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'a> InvariantExecutor<'a> {
801801
address: Address,
802802
targeted_contracts: &mut TargetedContracts,
803803
) -> Result<()> {
804-
for (address, (identifier, _)) in self.setup_contracts.iter() {
804+
for (address, (identifier, _)) in self.setup_contracts {
805805
if let Some(selectors) = self.artifact_filters.targeted.get(identifier) {
806806
self.add_address_with_functions(*address, selectors, false, targeted_contracts)?;
807807
}

Diff for: crates/evm/fuzz/src/invariant/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl FuzzRunIdentifiedContracts {
8484
pub fn clear_created_contracts(&self, created_contracts: Vec<Address>) {
8585
if !created_contracts.is_empty() {
8686
let mut targets = self.targets.lock();
87-
for addr in created_contracts.iter() {
87+
for addr in &created_contracts {
8888
targets.remove(addr);
8989
}
9090
}

Diff for: crates/evm/traces/src/decoder/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl CallTraceDecoder {
318318
pub async fn populate_traces(&self, traces: &mut Vec<CallTraceNode>) {
319319
for node in traces {
320320
node.trace.decoded = self.decode_function(&node.trace).await;
321-
for log in node.logs.iter_mut() {
321+
for log in &mut node.logs {
322322
log.decoded = self.decode_event(&log.raw_log).await;
323323
}
324324

@@ -682,7 +682,7 @@ fn reconstruct_params(event: &Event, decoded: &DecodedEvent) -> Vec<DynSolValue>
682682
let mut indexed = 0;
683683
let mut unindexed = 0;
684684
let mut inputs = vec![];
685-
for input in event.inputs.iter() {
685+
for input in &event.inputs {
686686
// Prevent panic of event `Transfer(from, to)` decoded with a signature
687687
// `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)` by making
688688
// sure the event inputs is not higher than decoded indexed / un-indexed values.

Diff for: crates/evm/traces/src/folded_stack_trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl FoldedStackTraceBuilder {
181181
/// the children function calls.
182182
fn build_without_subtraction(&mut self) -> Vec<String> {
183183
let mut lines = Vec::new();
184-
for TraceEntry { names, gas } in self.traces.iter() {
184+
for TraceEntry { names, gas } in &self.traces {
185185
lines.push(format!("{} {}", names.join(";"), gas));
186186
}
187187
lines

Diff for: crates/fmt/src/buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ mod tests {
431431
/* comment2 */ ",
432432
];
433433

434-
for content in contents.iter() {
434+
for content in &contents {
435435
let mut buf = FormatBuffer::new(String::new(), TAB_WIDTH);
436436
write!(buf, "{content}")?;
437437
assert_eq!(&buf.w, content);

Diff for: crates/fmt/src/formatter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ impl<'a, W: Write> Formatter<'a, W> {
18491849
}
18501850

18511851
// order all groups alphabetically
1852-
for group in import_groups.iter() {
1852+
for group in &import_groups {
18531853
// SAFETY: group is not empty
18541854
let first = group[0];
18551855
let last = group.last().copied().expect("group is not empty");

Diff for: crates/forge/src/cmd/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ mod tests {
799799
}
800800

801801
fn pick_creation_info(address: &str) -> Option<(&'static str, &'static str)> {
802-
for (addr, contract_name, creation_code) in CREATION_ARRAY.iter() {
802+
for (addr, contract_name, creation_code) in &CREATION_ARRAY {
803803
if address == *addr {
804804
return Some((contract_name, creation_code));
805805
}

0 commit comments

Comments
 (0)