Skip to content

Commit dafc553

Browse files
committed
save
1 parent f242b20 commit dafc553

File tree

59 files changed

+208
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+208
-198
lines changed

Cargo.toml

+14-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ repository = "https://github.com/foundry-rs/foundry"
3838
exclude = ["benches/", "tests/", "test-data/", "testdata/"]
3939

4040
[workspace.lints.clippy]
41-
dbg-macro = "warn"
41+
clear_with_drain = "warn"
42+
cloned_instead_of_copied = "warn"
43+
dbg_macro = "warn"
44+
derive_partial_eq_without_eq = "warn"
4245
explicit_into_iter_loop = "warn"
4346
explicit_iter_loop = "warn"
47+
flat_map_option = "warn"
4448
from_iter_instead_of_collect = "warn"
49+
if_not_else = "warn"
50+
if_then_some_else_none = "warn"
51+
implicit_clone = "warn"
52+
imprecise_flops = "warn"
53+
iter_on_empty_collections = "warn"
54+
iter_on_single_items = "warn"
55+
iter_with_drain = "warn"
56+
iter_without_into_iter = "warn"
57+
large_stack_frames = "warn"
4558
manual-string-new = "warn"
4659
uninlined-format-args = "warn"
4760
use-self = "warn"

crates/anvil/core/src/eth/transaction/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -999,10 +999,10 @@ impl Decodable for TypedTransaction {
999999
// Check byte after header
10001000
let ty = *h_decode_copy.first().ok_or(alloy_rlp::Error::Custom("empty slice"))?;
10011001

1002-
if ty != 0x7E {
1003-
Ok(TxEnvelope::decode(buf)?.into())
1004-
} else {
1002+
if ty == 0x7E {
10051003
Ok(Self::Deposit(DepositTransaction::decode_2718(buf)?))
1004+
} else {
1005+
Ok(TxEnvelope::decode(buf)?.into())
10061006
}
10071007
}
10081008
}

crates/anvil/src/eth/api.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ impl EthApi {
958958
node_info!("eth_signTransaction");
959959

960960
let from = request.from.map(Ok).unwrap_or_else(|| {
961-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
961+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
962962
})?;
963963

964964
let (nonce, _) = self.request_nonce(&request, from).await?;
@@ -986,7 +986,7 @@ impl EthApi {
986986
node_info!("eth_sendTransaction");
987987

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

@@ -2037,7 +2037,7 @@ impl EthApi {
20372037
};
20382038

20392039
let from = tx_req.from.map(Ok).unwrap_or_else(|| {
2040-
self.accounts()?.first().cloned().ok_or(BlockchainError::NoSignerAvailable)
2040+
self.accounts()?.first().copied().ok_or(BlockchainError::NoSignerAvailable)
20412041
})?;
20422042

20432043
// Get the nonce at the common block
@@ -2253,7 +2253,7 @@ impl EthApi {
22532253
}
22542254
}
22552255
}
2256-
block.transactions = BlockTransactions::Full(block_txs.to_vec());
2256+
block.transactions = BlockTransactions::Full(block_txs.clone());
22572257
blocks.push(block);
22582258
}
22592259
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1413,10 +1413,10 @@ impl Backend {
14131413
gas_priority_fee: max_priority_fee_per_gas.map(U256::from),
14141414
max_fee_per_blob_gas: max_fee_per_blob_gas
14151415
.or_else(|| {
1416-
if !blob_hashes.is_empty() {
1417-
env.block.get_blob_gasprice()
1418-
} else {
1416+
if blob_hashes.is_empty() {
14191417
None
1418+
} else {
1419+
env.block.get_blob_gasprice()
14201420
}
14211421
})
14221422
.map(U256::from),
@@ -2594,7 +2594,7 @@ impl Backend {
25942594
.zip(storage_proofs)
25952595
.map(|(key, proof)| {
25962596
let storage_key: U256 = key.into();
2597-
let value = account.storage.get(&storage_key).cloned().unwrap_or_default();
2597+
let value = account.storage.get(&storage_key).copied().unwrap_or_default();
25982598
StorageProof { key: JsonStorageKey::Hash(key), value, proof }
25992599
})
26002600
.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/cast/src/args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
184184
print_tokens(&tokens);
185185
}
186186
CastSubcommand::AbiEncode { sig, packed, args } => {
187-
if !packed {
188-
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
189-
} else {
187+
if packed {
190188
sh_println!("{}", SimpleCast::abi_encode_packed(&sig, &args)?)?
189+
} else {
190+
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
191191
}
192192
}
193193
CastSubcommand::DecodeCalldata { sig, calldata } => {

crates/cheatcodes/src/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Cheatcode for envOr_12Call {
239239
impl Cheatcode for envOr_13Call {
240240
fn apply(&self, _state: &mut Cheatcodes) -> Result {
241241
let Self { name, delim, defaultValue } = self;
242-
let default = defaultValue.to_vec();
242+
let default = defaultValue.clone();
243243
env_array_default(name, delim, &default, &DynSolType::Bytes)
244244
}
245245
}

crates/cheatcodes/src/inspector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1555,10 +1555,10 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
15551555
},
15561556
};
15571557

1558-
if count != expected.count {
1559-
Some((expected, count))
1560-
} else {
1558+
if count == expected.count {
15611559
None
1560+
} else {
1561+
Some((expected, count))
15621562
}
15631563
})
15641564
.collect::<Vec<_>>();

crates/cheatcodes/src/json.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,10 @@ fn encode(values: Vec<DynSolValue>) -> Vec<u8> {
493493
/// Canonicalize a json path key to always start from the root of the document.
494494
/// Read more about json path syntax: <https://goessner.net/articles/JsonPath/>
495495
pub(super) fn canonicalize_json_path(path: &str) -> Cow<'_, str> {
496-
if !path.starts_with('$') {
497-
format!("${path}").into()
498-
} else {
496+
if path.starts_with('$') {
499497
path.into()
498+
} else {
499+
format!("${path}").into()
500500
}
501501
}
502502

crates/cheatcodes/src/script.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl Wallets {
223223

224224
/// Locks inner Mutex and returns all signer addresses in the [MultiWallet].
225225
pub fn signers(&self) -> Result<Vec<Address>> {
226-
Ok(self.inner.lock().multi_wallet.signers()?.keys().cloned().collect())
226+
Ok(self.inner.lock().multi_wallet.signers()?.keys().copied().collect())
227227
}
228228

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

254-
let mut new_origin = new_origin.cloned();
254+
let mut new_origin = new_origin.copied();
255255

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

crates/cheatcodes/src/test/assert.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ fn assert_true(condition: bool) -> Result<Vec<u8>, SimpleAssertionError> {
456456
}
457457

458458
fn assert_false(condition: bool) -> Result<Vec<u8>, SimpleAssertionError> {
459-
if !condition {
460-
Ok(Default::default())
461-
} else {
459+
if condition {
462460
Err(SimpleAssertionError)
461+
} else {
462+
Ok(Default::default())
463463
}
464464
}
465465

@@ -472,10 +472,10 @@ fn assert_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a
472472
}
473473

474474
fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> {
475-
if left != right {
476-
Ok(Default::default())
477-
} else {
475+
if left == right {
478476
Err(ComparisonAssertionError::Ne { left, right })
477+
} else {
478+
Ok(Default::default())
479479
}
480480
}
481481

crates/chisel/src/session_source.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct IntermediateContract {
5959
type IntermediateContracts = HashMap<String, IntermediateContract>;
6060

6161
/// Full compilation output for the [SessionSource]
62-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
62+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6363
pub struct GeneratedOutput {
6464
/// The [IntermediateOutput] component
6565
pub intermediate: IntermediateOutput,
@@ -438,7 +438,7 @@ impl SessionSource {
438438
let Self { contract_name, global_code, top_level_code, run_code, config, .. } = self;
439439

440440
let script_import =
441-
if !config.no_vm { "import {Script} from \"forge-std/Script.sol\";\n" } else { "" };
441+
if config.no_vm { "" } else { "import {Script} from \"forge-std/Script.sol\";\n" };
442442

443443
format!(
444444
r#"

crates/common/fmt/src/console.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ impl ConsoleFmt for U256 {
222222
let integer = amount / exp10;
223223
let decimal = (amount % exp10).to_string();
224224
let decimal = format!("{decimal:0>log$}").trim_end_matches('0').to_string();
225-
if !decimal.is_empty() {
226-
format!("{integer}.{decimal}e{log}")
227-
} else {
225+
if decimal.is_empty() {
228226
format!("{integer}e{log}")
227+
} else {
228+
format!("{integer}.{decimal}e{log}")
229229
}
230230
}
231231
FormatSpec::Exponential(Some(precision)) => {
@@ -234,10 +234,10 @@ impl ConsoleFmt for U256 {
234234
let integer = amount / exp10;
235235
let decimal = (amount % exp10).to_string();
236236
let decimal = format!("{decimal:0>precision$}").trim_end_matches('0').to_string();
237-
if !decimal.is_empty() {
238-
format!("{integer}.{decimal}")
239-
} else {
237+
if decimal.is_empty() {
240238
format!("{integer}")
239+
} else {
240+
format!("{integer}.{decimal}")
241241
}
242242
}
243243
}
@@ -266,10 +266,10 @@ impl ConsoleFmt for I256 {
266266
let integer = (amount / exp10).twos_complement();
267267
let decimal = (amount % exp10).twos_complement().to_string();
268268
let decimal = format!("{decimal:0>log$}").trim_end_matches('0').to_string();
269-
if !decimal.is_empty() {
270-
format!("{sign}{integer}.{decimal}e{log}")
271-
} else {
269+
if decimal.is_empty() {
272270
format!("{sign}{integer}e{log}")
271+
} else {
272+
format!("{sign}{integer}.{decimal}e{log}")
273273
}
274274
}
275275
FormatSpec::Exponential(Some(precision)) => {
@@ -279,10 +279,10 @@ impl ConsoleFmt for I256 {
279279
let integer = (amount / exp10).twos_complement();
280280
let decimal = (amount % exp10).twos_complement().to_string();
281281
let decimal = format!("{decimal:0>precision$}").trim_end_matches('0').to_string();
282-
if !decimal.is_empty() {
283-
format!("{sign}{integer}.{decimal}")
284-
} else {
282+
if decimal.is_empty() {
285283
format!("{sign}{integer}")
284+
} else {
285+
format!("{sign}{integer}.{decimal}")
286286
}
287287
}
288288
}

crates/common/fmt/src/ui.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ impl<T: UIfmt> UIfmt for Option<T> {
5050

5151
impl<T: UIfmt> UIfmt for [T] {
5252
fn pretty(&self) -> String {
53-
if !self.is_empty() {
53+
if self.is_empty() {
54+
"[]".to_string()
55+
} else {
5456
let mut s = String::with_capacity(self.len() * 64);
5557
s.push_str("[\n");
5658
for item in self {
@@ -62,8 +64,6 @@ impl<T: UIfmt> UIfmt for [T] {
6264
}
6365
s.push(']');
6466
s
65-
} else {
66-
"[]".to_string()
6767
}
6868
}
6969
}

crates/common/src/compile.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ impl ProjectCompiler {
151151
// Taking is fine since we don't need these in `compile_with`.
152152
let files = std::mem::take(&mut self.files);
153153
self.compile_with(|| {
154-
let sources = if !files.is_empty() {
155-
Source::read_all(files)?
156-
} else {
154+
let sources = if files.is_empty() {
157155
project.paths.read_input_files()?
156+
} else {
157+
Source::read_all(files)?
158158
};
159159

160160
foundry_compilers::project::ProjectCompiler::with_sources(project, sources)?
@@ -580,7 +580,7 @@ impl PathOrContractInfo {
580580
/// Returns the path to the contract file if provided.
581581
pub fn path(&self) -> Option<PathBuf> {
582582
match self {
583-
Self::Path(path) => Some(path.to_path_buf()),
583+
Self::Path(path) => Some(path.clone()),
584584
Self::ContractInfo(info) => info.path.as_ref().map(PathBuf::from),
585585
}
586586
}

crates/common/src/contracts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl ContractsByArtifact {
264264
eyre::bail!("{id} has more than one implementation.");
265265
}
266266

267-
Ok(contracts.first().cloned())
267+
Ok(contracts.first().copied())
268268
}
269269

270270
/// 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/common/src/io/shell.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl TtyWidth {
7979
}
8080
}
8181

82-
#[derive(Debug, Default, Clone, Copy, PartialEq)]
82+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
8383
/// The requested output mode.
8484
pub enum OutputMode {
8585
/// Default output
@@ -104,7 +104,7 @@ impl OutputMode {
104104
}
105105

106106
/// The requested output format.
107-
#[derive(Debug, Default, Clone, Copy, PartialEq)]
107+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
108108
pub enum OutputFormat {
109109
/// Plain text output.
110110
#[default]
@@ -178,7 +178,7 @@ enum ShellOut {
178178
}
179179

180180
/// Whether messages should use color output.
181-
#[derive(Debug, Default, PartialEq, Clone, Copy, Serialize, Deserialize, ValueEnum)]
181+
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, ValueEnum)]
182182
pub enum ColorChoice {
183183
/// Intelligently guess whether to use color output (default).
184184
#[default]

0 commit comments

Comments
 (0)