Skip to content

Commit

Permalink
chore: fix more clippy (#8211)
Browse files Browse the repository at this point in the history
* chore: fix more clippy

* chore: missing lints.workspace

* docs
  • Loading branch information
DaniPopes authored Jun 20, 2024
1 parent bde40a8 commit 034393c
Show file tree
Hide file tree
Showing 45 changed files with 279 additions and 291 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ dbg-macro = "warn"
manual-string-new = "warn"
uninlined-format-args = "warn"
use-self = "warn"
redundant-clone = "warn"
octal-escapes = "allow"

[workspace.lints.rust]
rust-2018-idioms = "deny"
rust-2018-idioms = "warn"
# unreachable-pub = "warn"
unused-must-use = "deny"
unused-must-use = "warn"

[workspace.lints.rustdoc]
all = "warn"
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ mod tests {
let signature = Signature::from_str("0eb96ca19e8a77102767a41fc85a36afd5c61ccb09911cec5d3e86e193d9c5ae3a456401896b1b6055311536bf00a718568c744d8c1f9df59879e8350220ca182b").unwrap();

let tx = TypedTransaction::Legacy(Signed::new_unchecked(
tx.clone(),
tx,
signature,
b256!("a517b206d2223278f860ea017d3626cacad4f52ff51030dc9a96b432f17f8d34"),
));
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/server/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where
let pin = self.get_mut();
loop {
// drive the websocket
while let Poll::Ready(Ok(())) = pin.connection.poll_ready_unpin(cx) {
while matches!(pin.connection.poll_ready_unpin(cx), Poll::Ready(Ok(()))) {
// only start sending if socket is ready
if let Some(msg) = pin.pending.pop_front() {
if let Err(err) = pin.connection.start_send_unpin(msg) {
Expand Down
8 changes: 4 additions & 4 deletions crates/anvil/src/eth/otterscan/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct OtsSearchTransactions {
/// Otterscan format for listing relevant internal operations.
///
/// Ref: <https://github.com/otterscan/otterscan/blob/5adf4e3eead05eddb7746ee45b689161aaea7a7a/src/types.ts#L98>
#[derive(Debug, PartialEq, Serialize)]
#[derive(Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OtsInternalOperation {
pub r#type: OtsInternalOperationType,
Expand All @@ -91,7 +91,7 @@ pub struct OtsInternalOperation {
/// Types of internal operations recognized by Otterscan.
///
/// Ref: <https://github.com/otterscan/otterscan/blob/5adf4e3eead05eddb7746ee45b689161aaea7a7a/src/types.ts#L91>
#[derive(Debug, PartialEq, Serialize_repr)]
#[derive(Debug, PartialEq, Eq, Serialize_repr)]
#[repr(u8)]
pub enum OtsInternalOperationType {
Transfer = 0,
Expand All @@ -101,7 +101,7 @@ pub enum OtsInternalOperationType {
}

/// Otterscan's representation of a trace
#[derive(Debug, PartialEq, Serialize)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct OtsTrace {
pub r#type: OtsTraceType,
pub depth: usize,
Expand All @@ -115,7 +115,7 @@ pub struct OtsTrace {

/// The type of call being described by an Otterscan trace. Only CALL, STATICCALL and DELEGATECALL
/// are represented
#[derive(Debug, PartialEq, Serialize)]
#[derive(Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum OtsTraceType {
Call,
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn can_send_eip4844_transaction() {
let eip1559_est = provider.estimate_eip1559_fees(None).await.unwrap();
let gas_price = provider.get_gas_price().await.unwrap();

let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice("Hello World".as_bytes());
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Hello World");

let sidecar = sidecar.build().unwrap();
let tx = TransactionRequest::default()
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
utils::{http_provider, http_provider_with_signer},
};
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{address, Address, Bytes, TxKind, U256};
use alloy_primitives::{address, bytes, Address, Bytes, TxKind, U256};
use alloy_provider::Provider;
use alloy_rpc_types::{
anvil::Forking,
Expand Down Expand Up @@ -1191,7 +1191,7 @@ async fn test_fork_execution_reverted() {
.call(
WithOtherFields::new(TransactionRequest {
to: Some(TxKind::from(address!("Fd6CC4F251eaE6d02f9F7B41D1e80464D3d2F377"))),
input: TransactionInput::new("0x8f283b3c".as_bytes().into()),
input: TransactionInput::new(bytes!("8f283b3c")),
..Default::default()
}),
Some(target.into()),
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(clippy::octal_escapes)]
mod abi;
mod anvil;
mod anvil_api;
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl Cheatcodes {
}
_ => {
// if just starting with CREATE opcodes, record its inner frame gas
if let Some(None) = self.gas_metering_create {
if self.gas_metering_create == Some(None) {
self.gas_metering_create = Some(Some(interpreter.gas))
}

Expand Down
3 changes: 1 addition & 2 deletions crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ fn format_token(token: DynSolValue) -> String {
DynSolValue::Tuple(tokens) => {
let displayed_types = tokens
.iter()
.map(|t| t.sol_type_name().to_owned())
.map(|t| t.unwrap_or_default().into_owned())
.map(|t| t.sol_type_name().unwrap_or_default())
.collect::<Vec<_>>()
.join(", ");
let mut out =
Expand Down
2 changes: 1 addition & 1 deletion crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ contract {contract_name} {{
pt::Import::Rename(s, _, _) |
pt::Import::GlobalSymbol(s, _, _) => {
let s = match s {
pt::ImportPath::Filename(s) => s.string.clone(),
pt::ImportPath::Filename(s) => s.string,
pt::ImportPath::Path(p) => p.to_string(),
};
let path = PathBuf::from(s);
Expand Down
3 changes: 1 addition & 2 deletions crates/common/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ mod tests {
let param0 = B256::random();
let param1 = vec![3; 32];
let param2 = B256::random();
let log =
LogData::new_unchecked(vec![event.selector(), param0, param2], param1.clone().into());
let log = LogData::new_unchecked(vec![event.selector(), param0, param2], param1.into());
let event = get_indexed_event(event, &log);

assert_eq!(event.inputs.len(), 3);
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl ProviderBuilder {
initial_backoff,
compute_units_per_second,
);
let transport = RuntimeTransportBuilder::new(url.clone())
let transport = RuntimeTransportBuilder::new(url)
.with_timeout(timeout)
.with_headers(headers)
.with_jwt(jwt)
Expand Down Expand Up @@ -291,7 +291,7 @@ impl ProviderBuilder {
compute_units_per_second,
);

let transport = RuntimeTransportBuilder::new(url.clone())
let transport = RuntimeTransportBuilder::new(url)
.with_timeout(timeout)
.with_headers(headers)
.with_jwt(jwt)
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ pub async fn import_selectors(data: SelectorImportData) -> eyre::Result<Selector
OpenChainClient::new()?.import_selectors(data).await
}

#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Eq)]
pub struct ParsedSignatures {
pub signatures: RawSelectorImportData,
pub abis: Vec<JsonAbi>,
Expand Down
3 changes: 3 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
foundry-block-explorers = { workspace = true, features = ["foundry-compilers"] }
foundry-compilers = { workspace = true, features = ["svm-solc"] }
Expand Down
50 changes: 24 additions & 26 deletions crates/config/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl CachedChains {
/// Whether the `endpoint` matches
pub fn is_match(&self, chain: u64) -> bool {
match self {
CachedChains::All => true,
CachedChains::None => false,
CachedChains::Chains(chains) => chains.iter().any(|c| c.id() == chain),
Self::All => true,
Self::None => false,
Self::Chains(chains) => chains.iter().any(|c| c.id() == chain),
}
}
}
Expand All @@ -58,9 +58,9 @@ impl Serialize for CachedChains {
S: Serializer,
{
match self {
CachedChains::All => serializer.serialize_str("all"),
CachedChains::None => serializer.serialize_str("none"),
CachedChains::Chains(chains) => chains.serialize(serializer),
Self::All => serializer.serialize_str("all"),
Self::None => serializer.serialize_str("none"),
Self::Chains(chains) => chains.serialize(serializer),
}
}
}
Expand All @@ -79,11 +79,11 @@ impl<'de> Deserialize<'de> for CachedChains {

match Chains::deserialize(deserializer)? {
Chains::All(s) => match s.as_str() {
"all" => Ok(CachedChains::All),
"none" => Ok(CachedChains::None),
"all" => Ok(Self::All),
"none" => Ok(Self::None),
s => Err(serde::de::Error::unknown_variant(s, &["all", "none"])),
},
Chains::Chains(chains) => Ok(CachedChains::Chains(chains)),
Chains::Chains(chains) => Ok(Self::Chains(chains)),
}
}
}
Expand All @@ -105,21 +105,19 @@ impl CachedEndpoints {
pub fn is_match(&self, endpoint: impl AsRef<str>) -> bool {
let endpoint = endpoint.as_ref();
match self {
CachedEndpoints::All => true,
CachedEndpoints::Remote => {
!endpoint.contains("localhost:") && !endpoint.contains("127.0.0.1:")
}
CachedEndpoints::Pattern(re) => re.is_match(endpoint),
Self::All => true,
Self::Remote => !endpoint.contains("localhost:") && !endpoint.contains("127.0.0.1:"),
Self::Pattern(re) => re.is_match(endpoint),
}
}
}

impl PartialEq for CachedEndpoints {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(CachedEndpoints::Pattern(a), CachedEndpoints::Pattern(b)) => a.as_str() == b.as_str(),
(&CachedEndpoints::All, &CachedEndpoints::All) => true,
(&CachedEndpoints::Remote, &CachedEndpoints::Remote) => true,
(Self::Pattern(a), Self::Pattern(b)) => a.as_str() == b.as_str(),
(&Self::All, &Self::All) => true,
(&Self::Remote, &Self::Remote) => true,
_ => false,
}
}
Expand All @@ -130,9 +128,9 @@ impl Eq for CachedEndpoints {}
impl fmt::Display for CachedEndpoints {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CachedEndpoints::All => f.write_str("all"),
CachedEndpoints::Remote => f.write_str("remote"),
CachedEndpoints::Pattern(s) => s.fmt(f),
Self::All => f.write_str("all"),
Self::Remote => f.write_str("remote"),
Self::Pattern(s) => s.fmt(f),
}
}
}
Expand All @@ -142,9 +140,9 @@ impl FromStr for CachedEndpoints {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"all" => Ok(CachedEndpoints::All),
"remote" => Ok(CachedEndpoints::Remote),
_ => Ok(CachedEndpoints::Pattern(s.parse()?)),
"all" => Ok(Self::All),
"remote" => Ok(Self::Remote),
_ => Ok(Self::Pattern(s.parse()?)),
}
}
}
Expand All @@ -164,9 +162,9 @@ impl Serialize for CachedEndpoints {
S: Serializer,
{
match self {
CachedEndpoints::All => serializer.serialize_str("all"),
CachedEndpoints::Remote => serializer.serialize_str("remote"),
CachedEndpoints::Pattern(pattern) => serializer.serialize_str(pattern.as_str()),
Self::All => serializer.serialize_str("all"),
Self::Remote => serializer.serialize_str("remote"),
Self::Pattern(pattern) => serializer.serialize_str(pattern.as_str()),
}
}
}
Expand Down
Loading

0 comments on commit 034393c

Please sign in to comment.