diff --git a/Cargo.toml b/Cargo.toml index 976d34bd265ed..bb479060ab823 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,11 @@ repository = "https://github.com/foundry-rs/foundry" exclude = ["benches/", "tests/", "test-data/", "testdata/"] [workspace.lints.clippy] +borrow_as_ptr = "warn" +branches_sharing_code = "warn" +clear_with_drain = "warn" +cloned_instead_of_copied = "warn" +collection_is_never_read = "warn" dbg-macro = "warn" explicit_iter_loop = "warn" manual-string-new = "warn" diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index 428e54c80d9f9..31bb756afae27 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -988,7 +988,7 @@ impl EthApi { node_info!("eth_signTransaction"); let from = request.from.map(Ok).unwrap_or_else(|| { - self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable) + self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable) })?; let (nonce, _) = self.request_nonce(&request, from).await?; @@ -1016,7 +1016,7 @@ impl EthApi { node_info!("eth_sendTransaction"); let from = request.from.map(Ok).unwrap_or_else(|| { - self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable) + self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable) })?; let (nonce, on_chain_nonce) = self.request_nonce(&request, from).await?; @@ -2093,7 +2093,7 @@ impl EthApi { let from = tx_req.from.map(Ok).unwrap_or_else(|| { self.accounts()? .first() - .cloned() + .copied() .ok_or(BlockchainError::NoSignerAvailable) })?; diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index c21dec7022fd8..7ab05bd4154ed 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -967,8 +967,8 @@ impl Backend { // Defaults to block number for compatibility with existing state files. let fork_num_and_hash = self.get_fork().map(|f| (f.block_number(), f.block_hash())); + let best_number = state.best_block_number.unwrap_or(block.number.to::()); if let Some((number, hash)) = fork_num_and_hash { - let best_number = state.best_block_number.unwrap_or(block.number.to::()); trace!(target: "backend", state_block_number=?best_number, fork_block_number=?number); // If the state.block_number is greater than the fork block number, set best number // to the state block number. @@ -991,7 +991,6 @@ impl Backend { self.blockchain.storage.write().best_hash = hash; } } else { - let best_number = state.best_block_number.unwrap_or(block.number.to::()); self.blockchain.storage.write().best_number = best_number; // Set the current best block hash; @@ -1535,7 +1534,6 @@ impl Backend { let mut log_index = 0; let mut gas_used = 0; let mut transactions = Vec::with_capacity(calls.len()); - let mut receipts = Vec::new(); let mut logs= Vec::new(); // apply state overrides before executing the transactions if let Some(state_overrides) = state_overrides { @@ -1659,12 +1657,6 @@ impl Backend { }) .collect(), }; - let receipt = Receipt { - status: result.is_success().into(), - cumulative_gas_used: result.gas_used(), - logs:sim_res.logs.clone() - }; - receipts.push(receipt.with_bloom()); logs.extend(sim_res.logs.clone().iter().map(|log| log.inner.clone())); log_index += sim_res.logs.len(); call_res.push(sim_res); @@ -2881,7 +2873,7 @@ impl Backend { .zip(storage_proofs) .map(|(key, proof)| { let storage_key: U256 = key.into(); - let value = account.storage.get(&storage_key).cloned().unwrap_or_default(); + let value = account.storage.get(&storage_key).copied().unwrap_or_default(); StorageProof { key: JsonStorageKey::Hash(key), value, proof } }) .collect(), diff --git a/crates/anvil/src/eth/fees.rs b/crates/anvil/src/eth/fees.rs index bb405f62d1ef1..fc1f5980b0b1c 100644 --- a/crates/anvil/src/eth/fees.rs +++ b/crates/anvil/src/eth/fees.rs @@ -315,7 +315,7 @@ impl FeeHistoryService { .filter_map(|p| { let target_gas = (p * gas_used / 100f64) as u64; let mut sum_gas = 0; - for (gas_used, effective_reward) in transactions.iter().cloned() { + for (gas_used, effective_reward) in transactions.iter().copied() { sum_gas += gas_used; if target_gas <= sum_gas { return Some(effective_reward) diff --git a/crates/anvil/src/eth/otterscan/api.rs b/crates/anvil/src/eth/otterscan/api.rs index 227a8e421a260..058abc80fffd1 100644 --- a/crates/anvil/src/eth/otterscan/api.rs +++ b/crates/anvil/src/eth/otterscan/api.rs @@ -418,7 +418,7 @@ impl EthApi { txs.iter().skip(page * page_size).take(page_size).cloned().collect(), ), BlockTransactions::Hashes(txs) => BlockTransactions::Hashes( - txs.iter().skip(page * page_size).take(page_size).cloned().collect(), + txs.iter().skip(page * page_size).take(page_size).copied().collect(), ), BlockTransactions::Uncle => unreachable!(), }; diff --git a/crates/anvil/src/eth/pool/transactions.rs b/crates/anvil/src/eth/pool/transactions.rs index 36e421d7a50e1..69f101d7729ea 100644 --- a/crates/anvil/src/eth/pool/transactions.rs +++ b/crates/anvil/src/eth/pool/transactions.rs @@ -516,7 +516,7 @@ impl ReadyTransactions { } } - unlocked_tx.extend(to_remove.unlocks.iter().cloned()) + unlocked_tx.extend(to_remove.unlocks.iter().copied()) } } diff --git a/crates/anvil/src/eth/sign.rs b/crates/anvil/src/eth/sign.rs index e2ea036a0cafb..168cbb38dfaa4 100644 --- a/crates/anvil/src/eth/sign.rs +++ b/crates/anvil/src/eth/sign.rs @@ -52,7 +52,7 @@ pub struct DevSigner { impl DevSigner { pub fn new(accounts: Vec) -> Self { let addresses = accounts.iter().map(|wallet| wallet.address()).collect::>(); - let accounts = addresses.iter().cloned().zip(accounts).collect(); + let accounts = addresses.iter().copied().zip(accounts).collect(); Self { addresses, accounts } } } diff --git a/crates/anvil/tests/it/txpool.rs b/crates/anvil/tests/it/txpool.rs index c329b27fa9130..a883380a5f9aa 100644 --- a/crates/anvil/tests/it/txpool.rs +++ b/crates/anvil/tests/it/txpool.rs @@ -26,10 +26,8 @@ async fn geth_txpool() { let tx = WithOtherFields::new(tx); // send a few transactions - let mut txs = Vec::new(); for _ in 0..10 { - let tx_hash = provider.send_transaction(tx.clone()).await.unwrap(); - txs.push(tx_hash); + let _ = provider.send_transaction(tx.clone()).await.unwrap(); } // we gave a 20s block time, should be plenty for us to get the txpool's content diff --git a/crates/cheatcodes/src/script.rs b/crates/cheatcodes/src/script.rs index b3383992c19d8..ab6704f4ab562 100644 --- a/crates/cheatcodes/src/script.rs +++ b/crates/cheatcodes/src/script.rs @@ -253,7 +253,7 @@ impl Wallets { /// Locks inner Mutex and returns all signer addresses in the [MultiWallet]. pub fn signers(&self) -> Result> { - Ok(self.inner.lock().multi_wallet.signers()?.keys().cloned().collect()) + Ok(self.inner.lock().multi_wallet.signers()?.keys().copied().collect()) } /// Number of signers in the [MultiWallet]. @@ -281,7 +281,7 @@ fn broadcast(ccx: &mut CheatsCtxt, new_origin: Option<&Address>, single_call: bo ); ensure!(ccx.state.broadcast.is_none(), "a broadcast is active already"); - let mut new_origin = new_origin.cloned(); + let mut new_origin = new_origin.copied(); if new_origin.is_none() { let mut wallets = ccx.state.wallets().inner.lock(); diff --git a/crates/common/src/contracts.rs b/crates/common/src/contracts.rs index ecfb67d67f1cd..eaac3853b4c6e 100644 --- a/crates/common/src/contracts.rs +++ b/crates/common/src/contracts.rs @@ -280,7 +280,7 @@ impl ContractsByArtifact { eyre::bail!("{id} has more than one implementation."); } - Ok(contracts.first().cloned()) + Ok(contracts.first().copied()) } /// Finds abi for contract which has the same contract name or identifier as `id`. diff --git a/crates/common/src/fs.rs b/crates/common/src/fs.rs index 3d061759c50cf..19675e425a4ce 100644 --- a/crates/common/src/fs.rs +++ b/crates/common/src/fs.rs @@ -118,7 +118,7 @@ pub fn open(path: impl AsRef) -> Result { /// ref: pub fn normalize_path(path: &Path) -> PathBuf { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { components.next(); PathBuf::from(c.as_os_str()) } else { diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 2abb5a04cb233..ec05158f00d97 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1501,7 +1501,7 @@ impl Config { extra_output.push(ContractOutputSelection::Metadata); } - ConfigurableArtifacts::new(extra_output, self.extra_output_files.iter().cloned()) + ConfigurableArtifacts::new(extra_output, self.extra_output_files.iter().copied()) } /// Parses all libraries in the form of diff --git a/crates/doc/src/parser/comment.rs b/crates/doc/src/parser/comment.rs index bf2b0ad7b4f0d..9a64662665c31 100644 --- a/crates/doc/src/parser/comment.rs +++ b/crates/doc/src/parser/comment.rs @@ -170,13 +170,13 @@ impl<'a> CommentsRef<'a> { /// Filter a collection of comments and return only those that match provided tags. pub fn include_tags(&self, tags: &[CommentTag]) -> Self { // Cloning only references here - CommentsRef(self.iter().cloned().filter(|c| tags.contains(&c.tag)).collect()) + CommentsRef(self.iter().copied().filter(|c| tags.contains(&c.tag)).collect()) } /// Filter a collection of comments and return only those that do not match provided tags. pub fn exclude_tags(&self, tags: &[CommentTag]) -> Self { // Cloning only references here - CommentsRef(self.iter().cloned().filter(|c| !tags.contains(&c.tag)).collect()) + CommentsRef(self.iter().copied().filter(|c| !tags.contains(&c.tag)).collect()) } /// Check if the collection contains a target comment. @@ -200,7 +200,7 @@ impl<'a> CommentsRef<'a> { /// Filter a collection of comments and only return the custom tags. pub fn get_custom_tags(&self) -> Self { - CommentsRef(self.iter().cloned().filter(|c| c.is_custom()).collect()) + CommentsRef(self.iter().copied().filter(|c| c.is_custom()).collect()) } } diff --git a/crates/evm/fuzz/src/strategies/param.rs b/crates/evm/fuzz/src/strategies/param.rs index 43dcdae7b00f3..c292d42f9148f 100644 --- a/crates/evm/fuzz/src/strategies/param.rs +++ b/crates/evm/fuzz/src/strategies/param.rs @@ -135,9 +135,7 @@ pub fn fuzz_param_from_state( value() .prop_map(move |value| { let mut fuzzed_addr = Address::from_word(value); - if !deployed_libs.contains(&fuzzed_addr) { - DynSolValue::Address(fuzzed_addr) - } else { + if deployed_libs.contains(&fuzzed_addr) { let mut rng = StdRng::seed_from_u64(0x1337); // use deterministic rng // Do not use addresses of deployed libraries as fuzz input, instead return @@ -151,9 +149,8 @@ pub fn fuzz_param_from_state( break; } } - - DynSolValue::Address(fuzzed_addr) } + DynSolValue::Address(fuzzed_addr) }) .boxed() } diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 98a2adcef86c5..dc615bfc409c3 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -132,7 +132,7 @@ impl<'a, W: Write> Formatter<'a, W> { /// Casts the current writer `w` as a `String` reference. Should only be used for debugging. unsafe fn buf_contents(&self) -> &String { - *(&self.buf.w as *const W as *const &mut String) + *(&raw const self.buf.w as *const &mut String) } /// Casts the current `W` writer or the current temp buffer as a `String` reference. @@ -2093,15 +2093,7 @@ impl Visitor for Formatter<'_, W> { let (ident, string) = (ident.safe_unwrap(), string.safe_unwrap()); return_source_if_disabled!(self, loc, ';'); - let pragma_descriptor = if ident.name == "solidity" { - // There are some issues with parsing Solidity's versions with crates like `semver`: - // 1. Ranges like `>=0.4.21<0.6.0` or `>=0.4.21 <0.6.0` are not parseable at all. - // 2. Versions like `0.8.10` got transformed into `^0.8.10` which is not the same. - // TODO: semver-solidity crate :D - &string.string - } else { - &string.string - }; + let pragma_descriptor = &string.string; write_chunk!(self, string.loc.end(), "pragma {} {};", &ident.name, pragma_descriptor)?; diff --git a/crates/forge/src/cmd/clone.rs b/crates/forge/src/cmd/clone.rs index a5bc4b2aa4676..b1a28b60c70f5 100644 --- a/crates/forge/src/cmd/clone.rs +++ b/crates/forge/src/cmd/clone.rs @@ -556,10 +556,8 @@ fn dump_sources(meta: &Metadata, root: &PathBuf, no_reorg: bool) -> Result