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

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

+2-10
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

+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/anvil/tests/it/txpool.rs

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

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

+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/evm/fuzz/src/strategies/param.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ pub fn fuzz_param_from_state(
135135
value()
136136
.prop_map(move |value| {
137137
let mut fuzzed_addr = Address::from_word(value);
138-
if !deployed_libs.contains(&fuzzed_addr) {
139-
DynSolValue::Address(fuzzed_addr)
140-
} else {
138+
if deployed_libs.contains(&fuzzed_addr) {
141139
let mut rng = StdRng::seed_from_u64(0x1337); // use deterministic rng
142140

143141
// Do not use addresses of deployed libraries as fuzz input, instead return
@@ -151,9 +149,8 @@ pub fn fuzz_param_from_state(
151149
break;
152150
}
153151
}
154-
155-
DynSolValue::Address(fuzzed_addr)
156152
}
153+
DynSolValue::Address(fuzzed_addr)
157154
})
158155
.boxed()
159156
}

crates/fmt/src/formatter.rs

+2-10
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.
@@ -2093,15 +2093,7 @@ impl<W: Write> Visitor for Formatter<'_, W> {
20932093
let (ident, string) = (ident.safe_unwrap(), string.safe_unwrap());
20942094
return_source_if_disabled!(self, loc, ';');
20952095

2096-
let pragma_descriptor = if ident.name == "solidity" {
2097-
// There are some issues with parsing Solidity's versions with crates like `semver`:
2098-
// 1. Ranges like `>=0.4.21<0.6.0` or `>=0.4.21 <0.6.0` are not parseable at all.
2099-
// 2. Versions like `0.8.10` got transformed into `^0.8.10` which is not the same.
2100-
// TODO: semver-solidity crate :D
2101-
&string.string
2102-
} else {
2103-
&string.string
2104-
};
2096+
let pragma_descriptor = &string.string;
21052097

21062098
write_chunk!(self, string.loc.end(), "pragma {} {};", &ident.name, pragma_descriptor)?;
21072099

crates/forge/src/cmd/clone.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,8 @@ fn dump_sources(meta: &Metadata, root: &PathBuf, no_reorg: bool) -> Result<Vec<R
556556
PathBuf::from(&r.path)
557557
};
558558
r.path = new_path.to_string_lossy().to_string();
559-
remappings.push(r);
560-
} else {
561-
remappings.push(r);
562559
}
560+
remappings.push(r);
563561
}
564562

565563
Ok(remappings.into_iter().map(|r| r.into_relative(root)).collect())

crates/test-utils/src/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn initialize(target: &Path) {
237237

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

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

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

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

292292
// Release the write lock and acquire a new read lock.
293293
drop(write);
294-
_read = Some(lock.read().unwrap());
294+
_read = lock.read().unwrap();
295295
}
296296

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

0 commit comments

Comments
 (0)