Skip to content

Commit 0e3c1b7

Browse files
committed
feat: add some clippy lint
1 parent 9e5f4b9 commit 0e3c1b7

File tree

13 files changed

+22
-17
lines changed

13 files changed

+22
-17
lines changed

Cargo.toml

+5
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ impl EthApi {
962962
node_info!("eth_signTransaction");
963963

964964
let from = request.from.map(Ok).unwrap_or_else(|| {
965-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
965+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
966966
})?;
967967

968968
let (nonce, _) = self.request_nonce(&request, from).await?;
@@ -990,7 +990,7 @@ impl EthApi {
990990
node_info!("eth_sendTransaction");
991991

992992
let from = request.from.map(Ok).unwrap_or_else(|| {
993-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
993+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
994994
})?;
995995
let (nonce, on_chain_nonce) = self.request_nonce(&request, from).await?;
996996

@@ -2071,7 +2071,7 @@ impl EthApi {
20712071
};
20722072

20732073
let from = tx_req.from.map(Ok).unwrap_or_else(|| {
2074-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
2074+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
20752075
})?;
20762076

20772077
// Get the nonce at the common block

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,7 @@ impl Backend {
28472847
.zip(storage_proofs)
28482848
.map(|(key, proof)| {
28492849
let storage_key: U256 = key.into();
2850-
let value = account.storage.get(&storage_key).cloned().unwrap_or_default();
2850+
let value = account.storage.get(&storage_key).copied().unwrap_or_default();
28512851
StorageProof { key: JsonStorageKey::Hash(key), value, proof }
28522852
})
28532853
.collect(),

crates/anvil/src/eth/fees.rs

+1-1
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

+1-1
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

+1-1
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

+1-1
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/cheatcodes/src/script.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl Wallets {
246246

247247
/// Locks inner Mutex and returns all signer addresses in the [MultiWallet].
248248
pub fn signers(&self) -> Result<Vec<Address>> {
249-
Ok(self.inner.lock().multi_wallet.signers()?.keys().cloned().collect())
249+
Ok(self.inner.lock().multi_wallet.signers()?.keys().copied().collect())
250250
}
251251

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

277-
let mut new_origin = new_origin.cloned();
277+
let mut new_origin = new_origin.copied();
278278

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

crates/common/src/contracts.rs

+1-1
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`.

crates/common/src/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn open(path: impl AsRef<Path>) -> Result<fs::File> {
118118
/// ref: <https://github.com/rust-lang/cargo/blob/9ded34a558a900563b0acf3730e223c649cf859d/crates/cargo-util/src/paths.rs#L81>
119119
pub fn normalize_path(path: &Path) -> PathBuf {
120120
let mut components = path.components().peekable();
121-
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
121+
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() {
122122
components.next();
123123
PathBuf::from(c.as_os_str())
124124
} else {

crates/config/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ impl Config {
15011501
extra_output.push(ContractOutputSelection::Metadata);
15021502
}
15031503

1504-
ConfigurableArtifacts::new(extra_output, self.extra_output_files.iter().cloned())
1504+
ConfigurableArtifacts::new(extra_output, self.extra_output_files.iter().copied())
15051505
}
15061506

15071507
/// Parses all libraries in the form of

crates/doc/src/parser/comment.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ impl<'a> CommentsRef<'a> {
170170
/// Filter a collection of comments and return only those that match provided tags.
171171
pub fn include_tags(&self, tags: &[CommentTag]) -> Self {
172172
// Cloning only references here
173-
CommentsRef(self.iter().cloned().filter(|c| tags.contains(&c.tag)).collect())
173+
CommentsRef(self.iter().copied().filter(|c| tags.contains(&c.tag)).collect())
174174
}
175175

176176
/// Filter a collection of comments and return only those that do not match provided tags.
177177
pub fn exclude_tags(&self, tags: &[CommentTag]) -> Self {
178178
// Cloning only references here
179-
CommentsRef(self.iter().cloned().filter(|c| !tags.contains(&c.tag)).collect())
179+
CommentsRef(self.iter().copied().filter(|c| !tags.contains(&c.tag)).collect())
180180
}
181181

182182
/// Check if the collection contains a target comment.
@@ -200,7 +200,7 @@ impl<'a> CommentsRef<'a> {
200200

201201
/// Filter a collection of comments and only return the custom tags.
202202
pub fn get_custom_tags(&self) -> Self {
203-
CommentsRef(self.iter().cloned().filter(|c| c.is_custom()).collect())
203+
CommentsRef(self.iter().copied().filter(|c| c.is_custom()).collect())
204204
}
205205
}
206206

crates/fmt/src/formatter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, W: Write> Formatter<'a, W> {
132132

133133
/// Casts the current writer `w` as a `String` reference. Should only be used for debugging.
134134
unsafe fn buf_contents(&self) -> &String {
135-
*(&self.buf.w as *const W as *const &mut String)
135+
*(&raw const self.buf.w as *const &mut String)
136136
}
137137

138138
/// Casts the current `W` writer or the current temp buffer as a `String` reference.

0 commit comments

Comments
 (0)