Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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)
})?;

Expand Down
12 changes: 2 additions & 10 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<U64>());
Comment thread
taikoonwang marked this conversation as resolved.
Outdated
if let Some((number, hash)) = fork_num_and_hash {
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
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.
Expand All @@ -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::<U64>());
self.blockchain.storage.write().best_number = best_number;

// Set the current best block hash;
Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: collection is never read
    --> crates/anvil/src/eth/backend/mem/mod.rs:1537:17
     |
1537 |                 let mut receipts = Vec::new();

@grandizzy grandizzy Jun 5, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, looks like a leftover, added in 026b351 but not used anywhere @mattsse any insights if this should have been used?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also wondering this, the rest of the changes LGTM

let mut logs= Vec::new();
// apply state overrides before executing the transactions
if let Some(state_overrides) = state_overrides {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/otterscan/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/pool/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl ReadyTransactions {
}
}

unlocked_tx.extend(to_remove.unlocks.iter().cloned())
unlocked_tx.extend(to_remove.unlocks.iter().copied())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct DevSigner {
impl DevSigner {
pub fn new(accounts: Vec<PrivateKeySigner>) -> Self {
let addresses = accounts.iter().map(|wallet| wallet.address()).collect::<Vec<_>>();
let accounts = addresses.iter().cloned().zip(accounts).collect();
let accounts = addresses.iter().copied().zip(accounts).collect();
Self { addresses, accounts }
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/anvil/tests/it/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Wallets {

/// Locks inner Mutex and returns all signer addresses in the [MultiWallet].
pub fn signers(&self) -> Result<Vec<Address>> {
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].
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn open(path: impl AsRef<Path>) -> Result<fs::File> {
/// ref: <https://github.com/rust-lang/cargo/blob/9ded34a558a900563b0acf3730e223c649cf859d/crates/cargo-util/src/paths.rs#L81>
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions crates/doc/src/parser/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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())
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/evm/fuzz/src/strategies/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -151,9 +149,8 @@ pub fn fuzz_param_from_state(
break;
}
}

DynSolValue::Address(fuzzed_addr)
}
DynSolValue::Address(fuzzed_addr)
})
.boxed()
}
Expand Down
12 changes: 2 additions & 10 deletions crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2093,15 +2093,7 @@ impl<W: Write> 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)?;

Expand Down
4 changes: 1 addition & 3 deletions crates/forge/src/cmd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,8 @@ fn dump_sources(meta: &Metadata, root: &PathBuf, no_reorg: bool) -> Result<Vec<R
PathBuf::from(&r.path)
};
r.path = new_path.to_string_lossy().to_string();
remappings.push(r);
} else {
remappings.push(r);
}
remappings.push(r);
}

Ok(remappings.into_iter().map(|r| r.into_relative(root)).collect())
Expand Down
6 changes: 3 additions & 3 deletions crates/test-utils/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn initialize(target: &Path) {

// Initialize the global template if necessary.
let mut lock = crate::fd_lock::new_lock(TEMPLATE_LOCK.as_path());
let mut _read = Some(lock.read().unwrap());
let mut _read = lock.read().unwrap();
if fs::read(&*TEMPLATE_LOCK).unwrap() != b"1" {
// We are the first to acquire the lock:
// - initialize a new empty temp project;
Expand All @@ -248,7 +248,7 @@ pub fn initialize(target: &Path) {
// but `TempProject` does not currently allow this: https://github.com/foundry-rs/compilers/issues/22

// Release the read lock and acquire a write lock, initializing the lock file.
_read = None;
drop(_read);

let mut write = lock.write().unwrap();

Expand Down Expand Up @@ -291,7 +291,7 @@ pub fn initialize(target: &Path) {

// Release the write lock and acquire a new read lock.
drop(write);
_read = Some(lock.read().unwrap());
_read = lock.read().unwrap();
}

println!("- copying template dir from {}", tpath.display());
Expand Down