Skip to content

Commit bd4445d

Browse files
committed
feat: add some clippy lint
1 parent e0ad278 commit bd4445d

File tree

17 files changed

+31
-49
lines changed

17 files changed

+31
-49
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ repository = "https://github.com/foundry-rs/foundry"
3838
exclude = ["benches/", "tests/", "test-data/", "testdata/"]
3939

4040
[workspace.lints.clippy]
41+
borrow_as_ptr = "warn"
42+
branches_sharing_code = "warn"
43+
clear_with_drain = "warn"
44+
cloned_instead_of_copied = "warn"
45+
collection_is_never_read = "warn"
4146
dbg-macro = "warn"
4247
explicit_iter_loop = "warn"
4348
manual-string-new = "warn"

crates/anvil/src/eth/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ impl EthApi {
988988
node_info!("eth_signTransaction");
989989

990990
let from = request.from.map(Ok).unwrap_or_else(|| {
991-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
991+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
992992
})?;
993993

994994
let (nonce, _) = self.request_nonce(&request, from).await?;
@@ -1016,7 +1016,7 @@ impl EthApi {
10161016
node_info!("eth_sendTransaction");
10171017

10181018
let from = request.from.map(Ok).unwrap_or_else(|| {
1019-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
1019+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
10201020
})?;
10211021
let (nonce, on_chain_nonce) = self.request_nonce(&request, from).await?;
10221022

@@ -2093,7 +2093,7 @@ impl EthApi {
20932093
let from = tx_req.from.map(Ok).unwrap_or_else(|| {
20942094
self.accounts()?
20952095
.first()
2096-
.cloned()
2096+
.copied()
20972097
.ok_or(BlockchainError::NoSignerAvailable)
20982098
})?;
20992099

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ impl Backend {
967967
// Defaults to block number for compatibility with existing state files.
968968
let fork_num_and_hash = self.get_fork().map(|f| (f.block_number(), f.block_hash()));
969969

970+
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
970971
if let Some((number, hash)) = fork_num_and_hash {
971-
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
972972
trace!(target: "backend", state_block_number=?best_number, fork_block_number=?number);
973973
// If the state.block_number is greater than the fork block number, set best number
974974
// to the state block number.
@@ -991,7 +991,6 @@ impl Backend {
991991
self.blockchain.storage.write().best_hash = hash;
992992
}
993993
} else {
994-
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
995994
self.blockchain.storage.write().best_number = best_number;
996995

997996
// Set the current best block hash;
@@ -1535,7 +1534,6 @@ impl Backend {
15351534
let mut log_index = 0;
15361535
let mut gas_used = 0;
15371536
let mut transactions = Vec::with_capacity(calls.len());
1538-
let mut receipts = Vec::new();
15391537
let mut logs= Vec::new();
15401538
// apply state overrides before executing the transactions
15411539
if let Some(state_overrides) = state_overrides {
@@ -1659,12 +1657,6 @@ impl Backend {
16591657
})
16601658
.collect(),
16611659
};
1662-
let receipt = Receipt {
1663-
status: result.is_success().into(),
1664-
cumulative_gas_used: result.gas_used(),
1665-
logs:sim_res.logs.clone()
1666-
};
1667-
receipts.push(receipt.with_bloom());
16681660
logs.extend(sim_res.logs.clone().iter().map(|log| log.inner.clone()));
16691661
log_index += sim_res.logs.len();
16701662
call_res.push(sim_res);
@@ -2881,7 +2873,7 @@ impl Backend {
28812873
.zip(storage_proofs)
28822874
.map(|(key, proof)| {
28832875
let storage_key: U256 = key.into();
2884-
let value = account.storage.get(&storage_key).cloned().unwrap_or_default();
2876+
let value = account.storage.get(&storage_key).copied().unwrap_or_default();
28852877
StorageProof { key: JsonStorageKey::Hash(key), value, proof }
28862878
})
28872879
.collect(),

crates/anvil/src/eth/fees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl FeeHistoryService {
315315
.filter_map(|p| {
316316
let target_gas = (p * gas_used / 100f64) as u64;
317317
let mut sum_gas = 0;
318-
for (gas_used, effective_reward) in transactions.iter().cloned() {
318+
for (gas_used, effective_reward) in transactions.iter().copied() {
319319
sum_gas += gas_used;
320320
if target_gas <= sum_gas {
321321
return Some(effective_reward)

crates/anvil/src/eth/otterscan/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl EthApi {
418418
txs.iter().skip(page * page_size).take(page_size).cloned().collect(),
419419
),
420420
BlockTransactions::Hashes(txs) => BlockTransactions::Hashes(
421-
txs.iter().skip(page * page_size).take(page_size).cloned().collect(),
421+
txs.iter().skip(page * page_size).take(page_size).copied().collect(),
422422
),
423423
BlockTransactions::Uncle => unreachable!(),
424424
};

crates/anvil/src/eth/pool/transactions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl ReadyTransactions {
516516
}
517517
}
518518

519-
unlocked_tx.extend(to_remove.unlocks.iter().cloned())
519+
unlocked_tx.extend(to_remove.unlocks.iter().copied())
520520
}
521521
}
522522

crates/anvil/src/eth/sign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct DevSigner {
5252
impl DevSigner {
5353
pub fn new(accounts: Vec<PrivateKeySigner>) -> Self {
5454
let addresses = accounts.iter().map(|wallet| wallet.address()).collect::<Vec<_>>();
55-
let accounts = addresses.iter().cloned().zip(accounts).collect();
55+
let accounts = addresses.iter().copied().zip(accounts).collect();
5656
Self { addresses, accounts }
5757
}
5858
}

crates/anvil/tests/it/txpool.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ async fn geth_txpool() {
2626
let tx = WithOtherFields::new(tx);
2727

2828
// send a few transactions
29-
let mut txs = Vec::new();
3029
for _ in 0..10 {
31-
let tx_hash = provider.send_transaction(tx.clone()).await.unwrap();
32-
txs.push(tx_hash);
30+
let _ = provider.send_transaction(tx.clone()).await.unwrap();
3331
}
3432

3533
// we gave a 20s block time, should be plenty for us to get the txpool's content

crates/cheatcodes/src/script.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl Wallets {
253253

254254
/// Locks inner Mutex and returns all signer addresses in the [MultiWallet].
255255
pub fn signers(&self) -> Result<Vec<Address>> {
256-
Ok(self.inner.lock().multi_wallet.signers()?.keys().cloned().collect())
256+
Ok(self.inner.lock().multi_wallet.signers()?.keys().copied().collect())
257257
}
258258

259259
/// Number of signers in the [MultiWallet].
@@ -281,7 +281,7 @@ fn broadcast(ccx: &mut CheatsCtxt, new_origin: Option<&Address>, single_call: bo
281281
);
282282
ensure!(ccx.state.broadcast.is_none(), "a broadcast is active already");
283283

284-
let mut new_origin = new_origin.cloned();
284+
let mut new_origin = new_origin.copied();
285285

286286
if new_origin.is_none() {
287287
let mut wallets = ccx.state.wallets().inner.lock();

crates/common/src/contracts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl ContractsByArtifact {
280280
eyre::bail!("{id} has more than one implementation.");
281281
}
282282

283-
Ok(contracts.first().cloned())
283+
Ok(contracts.first().copied())
284284
}
285285

286286
/// Finds abi for contract which has the same contract name or identifier as `id`.

0 commit comments

Comments
 (0)