Skip to content

Commit b3ef467

Browse files
committed
save
1 parent f242b20 commit b3ef467

Some content is hidden

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

75 files changed

+315
-298
lines changed

Cargo.toml

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,71 @@ repository = "https://github.com/foundry-rs/foundry"
3838
exclude = ["benches/", "tests/", "test-data/", "testdata/"]
3939

4040
[workspace.lints.clippy]
41-
dbg-macro = "warn"
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"
46+
dbg_macro = "warn"
47+
derive_partial_eq_without_eq = "warn"
48+
empty_line_after_doc_comments = "warn"
49+
empty_line_after_outer_attr = "warn"
50+
enum_glob_use = "warn"
51+
equatable_if_let = "warn"
4252
explicit_into_iter_loop = "warn"
4353
explicit_iter_loop = "warn"
54+
flat_map_option = "warn"
4455
from_iter_instead_of_collect = "warn"
45-
manual-string-new = "warn"
46-
uninlined-format-args = "warn"
47-
use-self = "warn"
48-
redundant-clone = "warn"
49-
octal-escapes = "allow"
50-
# until <https://github.com/rust-lang/rust-clippy/issues/13885> is fixed
51-
literal-string-with-formatting-args = "allow"
56+
if_not_else = "warn"
57+
if_then_some_else_none = "warn"
58+
implicit_clone = "warn"
59+
imprecise_flops = "warn"
60+
iter_on_empty_collections = "warn"
61+
iter_on_single_items = "warn"
62+
iter_with_drain = "warn"
63+
iter_without_into_iter = "warn"
64+
large_stack_frames = "warn"
65+
manual_assert = "warn"
66+
manual_clamp = "warn"
67+
manual_is_variant_and = "warn"
68+
manual_string_new = "warn"
69+
match_same_arms = "warn"
70+
missing-const-for-fn = "allow" # TODO: https://github.com/rust-lang/rust-clippy/issues/14020
71+
mutex_integer = "warn"
72+
naive_bytecount = "warn"
73+
needless_bitwise_bool = "warn"
74+
needless_continue = "warn"
75+
needless_for_each = "warn"
76+
needless_pass_by_ref_mut = "warn"
77+
nonstandard_macro_braces = "warn"
78+
option_as_ref_cloned = "warn"
79+
or_fun_call = "warn"
80+
path_buf_push_overwrite = "warn"
81+
read_zero_byte_vec = "warn"
5282
result_large_err = "allow"
83+
redundant_clone = "warn"
84+
redundant_else = "warn"
85+
single_char_pattern = "warn"
86+
string_lit_as_bytes = "warn"
87+
string_lit_chars_any = "warn"
88+
suboptimal_flops = "warn"
89+
suspicious_operation_groupings = "warn"
90+
trailing_empty_array = "warn"
91+
trait_duplication_in_bounds = "warn"
92+
transmute_undefined_repr = "warn"
93+
trivial_regex = "warn"
94+
tuple_array_conversions = "warn"
95+
type_repetition_in_bounds = "warn"
96+
uninhabited_references = "warn"
97+
unnecessary_self_imports = "warn"
98+
unnecessary_struct_initialization = "warn"
99+
unnested_or_patterns = "warn"
100+
unused_peekable = "warn"
101+
unused_rounding = "warn"
102+
use_self = "warn"
103+
useless_let_if_seq = "warn"
104+
while_float = "warn"
105+
zero_sized_map_values = "warn"
53106

54107
[workspace.lints.rust]
55108
rust-2018-idioms = "warn"

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 7 additions & 5 deletions
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
}
@@ -3123,7 +3123,9 @@ impl TryFrom<Result<(InstructionResult, Option<Output>, u128, State)>> for GasEs
31233123
}
31243124
Err(err) => Err(err),
31253125
Ok((exit, output, gas, _)) => match exit {
3126-
return_ok!() | InstructionResult::CallOrCreate => Ok(Self::Success(gas)),
3126+
InstructionResult::Continue | InstructionResult::Stop |
3127+
InstructionResult::Return | InstructionResult::SelfDestruct |
3128+
InstructionResult::ReturnContract | InstructionResult::CallOrCreate => Ok(Self::Success(gas)),
31273129

31283130
InstructionResult::Revert => Ok(Self::Revert(output.map(|o| o.into_data()))),
31293131

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 6 deletions
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/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub async fn run_command(args: Chisel) -> Result<()> {
7878
}
7979
return Ok(())
8080
}
81-
Some(ChiselSubcommand::Load { id }) | Some(ChiselSubcommand::View { id }) => {
81+
Some(ChiselSubcommand::Load { id } | ChiselSubcommand::View { id }) => {
8282
// For both of these subcommands, we need to attempt to load the session from cache
8383
match dispatcher.dispatch_command(ChiselCommand::Load, &[id]).await {
8484
DispatchResult::CommandSuccess(_) => { /* Continue */ }

crates/chisel/src/executor.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,8 @@ impl Type {
681681
pt::Expression::Multiply(_, lhs, rhs) |
682682
pt::Expression::Divide(_, lhs, rhs) => {
683683
match (Self::ethabi(lhs, None), Self::ethabi(rhs, None)) {
684-
(Some(DynSolType::Int(_)), Some(DynSolType::Int(_))) |
685-
(Some(DynSolType::Int(_)), Some(DynSolType::Uint(_))) |
686-
(Some(DynSolType::Uint(_)), Some(DynSolType::Int(_))) => {
684+
(Some(DynSolType::Int(_) | DynSolType::Uint(_)), Some(DynSolType::Int(_))) |
685+
(Some(DynSolType::Int(_)), Some(DynSolType::Uint(_))) => {
687686
Some(Self::Builtin(DynSolType::Int(256)))
688687
}
689688
_ => {
@@ -953,7 +952,7 @@ impl Type {
953952
custom_type: &mut Vec<String>,
954953
contract_name: Option<String>,
955954
) -> Result<Option<DynSolType>> {
956-
if let Some("this") | Some("super") = custom_type.last().map(String::as_str) {
955+
if let Some("this" | "super") = custom_type.last().map(String::as_str) {
957956
custom_type.pop();
958957
}
959958
if custom_type.is_empty() {
@@ -1210,12 +1209,10 @@ impl Type {
12101209
match self {
12111210
Self::Array(inner) | Self::FixedArray(inner, _) | Self::ArrayIndex(inner, _) => {
12121211
match inner.try_as_ethabi(intermediate) {
1213-
Some(DynSolType::Array(inner)) | Some(DynSolType::FixedArray(inner, _)) => {
1212+
Some(DynSolType::Array(inner) | DynSolType::FixedArray(inner, _)) => {
12141213
Some(*inner)
12151214
}
1216-
Some(DynSolType::Bytes) |
1217-
Some(DynSolType::String) |
1218-
Some(DynSolType::FixedBytes(_)) => Some(DynSolType::FixedBytes(1)),
1215+
Some(DynSolType::Bytes | DynSolType::String | DynSolType::FixedBytes(_)) => Some(DynSolType::FixedBytes(1)),
12191216
ty => ty,
12201217
}
12211218
}
@@ -1240,10 +1237,8 @@ impl Type {
12401237
fn is_array(&self) -> bool {
12411238
matches!(
12421239
self,
1243-
Self::Array(_) |
1244-
Self::FixedArray(_, _) |
1245-
Self::Builtin(DynSolType::Array(_)) |
1246-
Self::Builtin(DynSolType::FixedArray(_, _))
1240+
Self::Array(_) | Self::FixedArray(_, _) |
1241+
Self::Builtin(DynSolType::Array(_) | DynSolType::FixedArray(_, _))
12471242
)
12481243
}
12491244

@@ -1272,7 +1267,7 @@ fn func_members(func: &pt::FunctionDefinition, custom_type: &[String]) -> Option
12721267
_ => None,
12731268
});
12741269
match vis {
1275-
Some(pt::Visibility::External(_)) | Some(pt::Visibility::Public(_)) => {
1270+
Some(pt::Visibility::External(_) | pt::Visibility::Public(_)) => {
12761271
match custom_type.first().unwrap().as_str() {
12771272
"address" => Some(DynSolType::Address),
12781273
"selector" => Some(DynSolType::FixedBytes(4)),

crates/chisel/src/session_source.rs

Lines changed: 2 additions & 2 deletions
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/chisel/src/solidity_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl Helper for SolidityHelper {}
246246
fn token_style(token: &Token) -> Style {
247247
use solar_parse::{
248248
interface::kw::*,
249-
token::{TokenKind::*, TokenLitKind::*},
249+
token::{TokenKind::{Arrow, Comment, FatArrow, Ident, Literal}, TokenLitKind::{HexStr, Str, UnicodeStr}},
250250
};
251251

252252
match token.kind {

0 commit comments

Comments
 (0)