From f2099a8eaaf16dc6fca1a7a81ba7980c3ecc15e7 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 16 Jan 2023 18:11:27 -0800 Subject: [PATCH] chore: fix clippy (#2059) --- .../ethers-contract-abigen/src/filter.rs | 9 ++--- .../ethers-contract-abigen/src/lib.rs | 1 - ethers-contract/src/multicall/mod.rs | 2 +- ethers-etherscan/src/account.rs | 18 +++------- ethers-providers/src/transports/quorum.rs | 9 ++--- ethers-solc/src/artifacts/mod.rs | 36 +++++-------------- ethers-solc/src/filter.rs | 8 ++--- ethers-solc/src/resolver/tree.rs | 19 +++------- 8 files changed, 24 insertions(+), 78 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/src/filter.rs b/ethers-contract/ethers-contract-abigen/src/filter.rs index d071ac87..1a97c728 100644 --- a/ethers-contract/ethers-contract-abigen/src/filter.rs +++ b/ethers-contract/ethers-contract-abigen/src/filter.rs @@ -4,9 +4,10 @@ use regex::Regex; use std::collections::HashSet; /// Used to filter contracts that should be _included_ in the abigen generation. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] pub enum ContractFilter { /// Include all contracts + #[default] All, /// Only include contracts that match the filter Select(SelectContracts), @@ -27,12 +28,6 @@ impl ContractFilter { } } -impl Default for ContractFilter { - fn default() -> Self { - ContractFilter::All - } -} - impl From for ContractFilter { fn from(f: SelectContracts) -> Self { ContractFilter::Select(f) diff --git a/ethers-contract/ethers-contract-abigen/src/lib.rs b/ethers-contract/ethers-contract-abigen/src/lib.rs index beeb04b7..2b5706da 100644 --- a/ethers-contract/ethers-contract-abigen/src/lib.rs +++ b/ethers-contract/ethers-contract-abigen/src/lib.rs @@ -152,7 +152,6 @@ impl Abigen { self } - #[must_use] #[deprecated = "Use format instead"] #[doc(hidden)] pub fn rustfmt(mut self, rustfmt: bool) -> Self { diff --git a/ethers-contract/src/multicall/mod.rs b/ethers-contract/src/multicall/mod.rs index 76106d36..513f1776 100644 --- a/ethers-contract/src/multicall/mod.rs +++ b/ethers-contract/src/multicall/mod.rs @@ -282,7 +282,7 @@ impl Clone for Multicall { contract: self.contract.clone(), version: self.version, legacy: self.legacy, - block: self.block.clone(), + block: self.block, calls: self.calls.clone(), } } diff --git a/ethers-etherscan/src/account.rs b/ethers-etherscan/src/account.rs index aa096d7c..92965031 100644 --- a/ethers-etherscan/src/account.rs +++ b/ethers-etherscan/src/account.rs @@ -355,10 +355,11 @@ pub struct MinedBlock { } /// The pre-defined block parameter for balance API endpoints -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] pub enum Tag { Earliest, Pending, + #[default] Latest, } @@ -372,12 +373,6 @@ impl Display for Tag { } } -impl Default for Tag { - fn default() -> Self { - Tag::Latest - } -} - /// The list sorting preference #[derive(Clone, Copy, Debug)] pub enum Sort { @@ -466,8 +461,9 @@ impl TokenQueryOption { } /// The pre-defined block type for retrieving mined blocks -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] pub enum BlockType { + #[default] CanonicalBlocks, Uncles, } @@ -481,12 +477,6 @@ impl Display for BlockType { } } -impl Default for BlockType { - fn default() -> Self { - BlockType::CanonicalBlocks - } -} - impl Client { /// Returns the Ether balance of a given address. /// diff --git a/ethers-providers/src/transports/quorum.rs b/ethers-providers/src/transports/quorum.rs index 3faf58b9..23702374 100644 --- a/ethers-providers/src/transports/quorum.rs +++ b/ethers-providers/src/transports/quorum.rs @@ -214,12 +214,13 @@ impl QuorumProvider { } /// Determines when the provider reached a quorum -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub enum Quorum { /// The quorum is reached when all providers return the exact value All, /// The quorum is reached when the majority of the providers have returned a /// matching value, taking into account their weight. + #[default] Majority, /// The quorum is reached when the cumulative weight of a matching return /// exceeds the given percentage of the total weight. @@ -257,12 +258,6 @@ impl Quorum { } } -impl Default for Quorum { - fn default() -> Self { - Quorum::Majority - } -} - // A future that returns the provider's response and it's index within the // `QuorumProvider` provider set #[cfg(target_arch = "wasm32")] diff --git a/ethers-solc/src/artifacts/mod.rs b/ethers-solc/src/artifacts/mod.rs index 7b7985be..94806f9c 100644 --- a/ethers-solc/src/artifacts/mod.rs +++ b/ethers-solc/src/artifacts/mod.rs @@ -677,7 +677,7 @@ pub struct YulDetails { pub optimizer_steps: Option, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub enum EvmVersion { Homestead, TangerineWhistle, @@ -687,15 +687,10 @@ pub enum EvmVersion { Petersburg, Istanbul, Berlin, + #[default] London, } -impl Default for EvmVersion { - fn default() -> Self { - Self::London - } -} - impl EvmVersion { /// Checks against the given solidity `semver::Version` pub fn normalize_version(self, version: &Version) -> Option { @@ -786,9 +781,10 @@ pub struct DebuggingSettings { } /// How to treat revert (and require) reason strings. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub enum RevertStrings { /// "default" does not inject compiler-generated revert strings and keeps user-supplied ones. + #[default] Default, /// "strip" removes all revert strings (if possible, i.e. if literals are used) keeping /// side-effects @@ -827,12 +823,6 @@ impl FromStr for RevertStrings { } } -impl Default for RevertStrings { - fn default() -> Self { - RevertStrings::Default - } -} - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SettingsMetadata { /// Use only literal content and not URLs (false by default) @@ -868,19 +858,14 @@ impl From for SettingsMetadata { /// Determines the hash method for the metadata hash that is appended to the bytecode. /// /// Solc's default is `Ipfs`, see . -#[derive(Clone, Debug, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum BytecodeHash { + #[default] Ipfs, None, Bzzr1, } -impl Default for BytecodeHash { - fn default() -> Self { - BytecodeHash::Ipfs - } -} - impl FromStr for BytecodeHash { type Err = String; @@ -1036,8 +1021,9 @@ pub struct ModelCheckerSettings { } /// Which model checker engine to run. -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub enum ModelCheckerEngine { + #[default] Default, All, BMC, @@ -1070,12 +1056,6 @@ impl FromStr for ModelCheckerEngine { } } -impl Default for ModelCheckerEngine { - fn default() -> Self { - ModelCheckerEngine::Default - } -} - /// Which model checker targets to check. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/ethers-solc/src/filter.rs b/ethers-solc/src/filter.rs index 42cce5ff..604414bb 100644 --- a/ethers-solc/src/filter.rs +++ b/ethers-solc/src/filter.rs @@ -53,11 +53,13 @@ impl FileFilter for TestFileFilter { /// A type that can apply a filter to a set of preprocessed [FilteredSources] in order to set sparse /// output for specific files +#[derive(Default)] pub enum SparseOutputFilter { /// Sets the configured [OutputSelection] for dirty files only. /// /// In other words, we request the output of solc only for files that have been detected as /// _dirty_. + #[default] AllDirty, /// Apply an additional filter to [FilteredSources] to Custom(Box), @@ -176,12 +178,6 @@ impl From> for SparseOutputFilter { } } -impl Default for SparseOutputFilter { - fn default() -> Self { - SparseOutputFilter::AllDirty - } -} - impl fmt::Debug for SparseOutputFilter { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { diff --git a/ethers-solc/src/resolver/tree.rs b/ethers-solc/src/resolver/tree.rs index 829dc0c0..9e88fadc 100644 --- a/ethers-solc/src/resolver/tree.rs +++ b/ethers-solc/src/resolver/tree.rs @@ -1,25 +1,16 @@ use crate::Graph; use std::{collections::HashSet, io, io::Write, str::FromStr}; -#[derive(Debug, Clone, Copy, Eq, PartialEq)] +#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)] pub enum Charset { + // when operating in a console on windows non-UTF-8 byte sequences are not supported on + // stdout, See also [`StdoutLock`] + #[cfg_attr(target_os = "windows", default)] Utf8, + #[cfg_attr(not(target_os = "windows"), default)] Ascii, } -impl Default for Charset { - fn default() -> Self { - // when operating in a console on windows non-UTF-8 byte sequences are not supported on - // stdout, See also [`StdoutLock`] - #[cfg(target_os = "windows")] - { - Charset::Ascii - } - #[cfg(not(target_os = "windows"))] - Charset::Utf8 - } -} - impl FromStr for Charset { type Err = String;