From e24117a1e1d6301d80101c7cc83c93ac4a8b1258 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 19 Dec 2021 05:28:38 +0100 Subject: [PATCH] chore(clippy): make clippy happy (#705) --- .../ethers-contract-abigen/src/lib.rs | 4 ++++ ethers-contract/src/call.rs | 2 ++ ethers-contract/src/contract.rs | 2 ++ ethers-contract/src/event.rs | 2 ++ ethers-contract/src/factory.rs | 3 +++ ethers-contract/src/multicall/mod.rs | 2 ++ ethers-core/src/types/i256.rs | 24 ++++++++++++++++++- ethers-core/src/types/log.rs | 14 +++++++++++ ethers-core/src/types/trace/filter.rs | 6 +++++ ethers-core/src/types/transaction/eip1559.rs | 9 +++++++ ethers-core/src/types/transaction/eip2930.rs | 2 +- ethers-core/src/types/transaction/eip712.rs | 1 + ethers-core/src/types/transaction/request.rs | 10 ++++++++ ethers-core/src/utils/ganache.rs | 6 +++++ ethers-core/src/utils/geth.rs | 3 +++ ethers-etherscan/src/contract.rs | 8 +++++++ .../src/gas_oracle/eth_gas_station.rs | 1 + .../src/gas_oracle/etherchain.rs | 1 + ethers-middleware/src/gas_oracle/etherscan.rs | 1 + ethers-middleware/src/signer.rs | 1 + ethers-providers/src/pending_escalator.rs | 2 ++ ethers-providers/src/pending_transaction.rs | 2 ++ ethers-providers/src/provider.rs | 3 +++ ethers-providers/src/stream.rs | 2 ++ ethers-signers/src/lib.rs | 1 + ethers-signers/src/trezor/app.rs | 2 +- ethers-signers/src/wallet/mnemonic.rs | 4 ++++ ethers-solc/src/artifacts.rs | 5 ++++ ethers-solc/src/cache.rs | 3 +++ ethers-solc/src/compile.rs | 2 ++ ethers-solc/src/lib.rs | 11 +++++++++ 31 files changed, 136 insertions(+), 3 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/src/lib.rs b/ethers-contract/ethers-contract-abigen/src/lib.rs index 238d78d1..ef243408 100644 --- a/ethers-contract/ethers-contract-abigen/src/lib.rs +++ b/ethers-contract/ethers-contract-abigen/src/lib.rs @@ -81,6 +81,7 @@ impl Abigen { /// Manually adds a solidity event alias to specify what the event struct /// and function name will be in Rust. + #[must_use] pub fn add_event_alias(mut self, signature: S1, alias: S2) -> Self where S1: Into, @@ -93,6 +94,7 @@ impl Abigen { /// Manually adds a solidity method alias to specify what the method name /// will be in Rust. For solidity methods without an alias, the snake cased /// method name will be used. + #[must_use] pub fn add_method_alias(mut self, signature: S1, alias: S2) -> Self where S1: Into, @@ -107,6 +109,7 @@ impl Abigen { /// /// Note that in case `rustfmt` does not exist or produces an error, the /// unformatted code will be used. + #[must_use] pub fn rustfmt(mut self, rustfmt: bool) -> Self { self.rustfmt = rustfmt; self @@ -116,6 +119,7 @@ impl Abigen { /// /// This makes it possible to for example derive serde::Serialize and /// serde::Deserialize for events. + #[must_use] pub fn add_event_derive(mut self, derive: S) -> Self where S: Into, diff --git a/ethers-contract/src/call.rs b/ethers-contract/src/call.rs index 22228369..0abdc23e 100644 --- a/ethers-contract/src/call.rs +++ b/ethers-contract/src/call.rs @@ -1,3 +1,5 @@ +#![allow(clippy::return_self_not_must_use)] + use super::base::{decode_function_data, AbiError}; use ethers_core::{ abi::{AbiDecode, AbiEncode, Detokenize, Function, InvalidOutputType, Tokenizable}, diff --git a/ethers-contract/src/contract.rs b/ethers-contract/src/contract.rs index 43f60c5f..de909145 100644 --- a/ethers-contract/src/contract.rs +++ b/ethers-contract/src/contract.rs @@ -247,6 +247,7 @@ impl Contract { /// Returns a new contract instance at `address`. /// /// Clones `self` internally + #[must_use] pub fn at>(&self, address: T) -> Self where M: Clone, @@ -259,6 +260,7 @@ impl Contract { /// Returns a new contract instance using the provided client /// /// Clones `self` internally + #[must_use] pub fn connect(&self, client: Arc) -> Self where M: Clone, diff --git a/ethers-contract/src/event.rs b/ethers-contract/src/event.rs index dc88d78a..370bcd70 100644 --- a/ethers-contract/src/event.rs +++ b/ethers-contract/src/event.rs @@ -1,3 +1,5 @@ +#![allow(clippy::return_self_not_must_use)] + use crate::{log::LogMeta, stream::EventStream, ContractError, EthLogDecode}; use ethers_core::{ diff --git a/ethers-contract/src/factory.rs b/ethers-contract/src/factory.rs index bca08aea..eee777bc 100644 --- a/ethers-contract/src/factory.rs +++ b/ethers-contract/src/factory.rs @@ -24,17 +24,20 @@ pub struct Deployer { impl Deployer { /// Sets the number of confirmations to wait for the contract deployment transaction + #[must_use] pub fn confirmations>(mut self, confirmations: T) -> Self { self.confs = confirmations.into(); self } + #[must_use] pub fn block>(mut self, block: T) -> Self { self.block = block.into(); self } /// Uses a Legacy transaction instead of an EIP-1559 one to do the deployment + #[must_use] pub fn legacy(mut self) -> Self { self.tx = match self.tx { TypedTransaction::Eip1559(inner) => { diff --git a/ethers-contract/src/multicall/mod.rs b/ethers-contract/src/multicall/mod.rs index ebc4225d..61ca2701 100644 --- a/ethers-contract/src/multicall/mod.rs +++ b/ethers-contract/src/multicall/mod.rs @@ -173,12 +173,14 @@ impl Multicall { } /// Makes a legacy transaction instead of an EIP-1559 one + #[must_use] pub fn legacy(mut self) -> Self { self.legacy = true; self } /// Sets the `block` field for the multicall aggregate call + #[must_use] pub fn block>(mut self, block: T) -> Self { self.block = Some(block.into()); self diff --git a/ethers-core/src/types/i256.rs b/ethers-core/src/types/i256.rs index 03fdd84b..9a115545 100644 --- a/ethers-core/src/types/i256.rs +++ b/ethers-core/src/types/i256.rs @@ -329,6 +329,7 @@ impl I256 { } /// Returns the sign of the number. + #[must_use] pub fn signum(self) -> Self { self.signum64().into() } @@ -370,6 +371,7 @@ impl I256 { /// # Panics /// /// In debug mode, will panic if it overflows. + #[must_use] pub fn abs(self) -> Self { handle_overflow(self.overflowing_abs()) } @@ -402,12 +404,14 @@ impl I256 { /// Saturating absolute value. Computes `self.abs()`, returning `MAX` if /// `self == MIN` instead of overflowing. + #[must_use] pub fn saturating_abs(self) -> Self { self.checked_abs().unwrap_or(I256::MAX) } /// Wrapping absolute value. Computes `self.abs()`, wrapping around at the /// boundary of the type. + #[must_use] pub fn wrapping_abs(self) -> Self { let (result, _) = self.overflowing_abs(); result @@ -446,12 +450,14 @@ impl I256 { /// Saturating negation. Computes `self.neg()`, returning `MAX` if /// `self == MIN` instead of overflowing. + #[must_use] pub fn saturating_neg(self) -> Self { self.checked_neg().unwrap_or(I256::MAX) } /// Wrapping negation. Computes `self.neg()`, returning `MIN` if /// `self == MIN` instead of overflowing. + #[must_use] pub fn wrapping_neg(self) -> Self { let (result, _) = self.overflowing_neg(); result @@ -567,6 +573,7 @@ impl I256 { } /// Addition which saturates at the maximum value (Self::max_value()). + #[must_use] pub fn saturating_add(self, other: Self) -> Self { let (result, overflow) = self.overflowing_add(other); if overflow { @@ -580,6 +587,7 @@ impl I256 { } /// Wrapping addition. + #[must_use] pub fn wrapping_add(self, other: Self) -> Self { let (result, _) = self.overflowing_add(other); result @@ -620,6 +628,7 @@ impl I256 { } /// Subtraction which saturates at zero. + #[must_use] pub fn saturating_sub(self, other: Self) -> Self { let (result, overflow) = self.overflowing_sub(other); if overflow { @@ -633,6 +642,7 @@ impl I256 { } /// Wrapping subtraction. + #[must_use] pub fn wrapping_sub(self, other: Self) -> Self { let (result, _) = self.overflowing_sub(other); result @@ -662,6 +672,7 @@ impl I256 { } /// Multiplication which saturates at the maximum value.. + #[must_use] pub fn saturating_mul(self, rhs: Self) -> Self { self.checked_mul(rhs).unwrap_or_else(|| { match Sign::from_signum64(self.signum64() * rhs.signum64()) { @@ -672,6 +683,7 @@ impl I256 { } /// Wrapping multiplication. + #[must_use] pub fn wrapping_mul(self, rhs: Self) -> Self { let (result, _) = self.overflowing_mul(rhs); result @@ -702,12 +714,14 @@ impl I256 { } /// Division which saturates at the maximum value. + #[must_use] pub fn saturating_div(self, rhs: Self) -> Self { // There is only one overflow (I256::MIN / -1 = I256::MAX) self.checked_div(rhs).unwrap_or(I256::MAX) } /// Wrapping division. + #[must_use] pub fn wrapping_div(self, rhs: Self) -> Self { self.overflowing_div(rhs).0 } @@ -737,6 +751,7 @@ impl I256 { /// Wrapping remainder. Returns the result of the operation % /// regardless of whether or not the division overflowed. + #[must_use] pub fn wrapping_rem(self, rhs: Self) -> Self { self.overflowing_rem(rhs).0 } @@ -749,6 +764,7 @@ impl I256 { /// rhs`: /// * If `self > 0`, this is equal to round towards zero (the default in Rust); /// * If `self < 0`, this is equal to round towards +/- infinity. + #[must_use] pub fn div_euclid(self, rhs: Self) -> Self { let q = self / rhs; if (self % rhs).is_negative() { @@ -761,6 +777,7 @@ impl I256 { /// This is done as if by the _Euclidean division algorithm_ /// given `r = self.rem_euclid(rhs)`, `self = rhs * self.div_euclid(rhs) + r, and 0 <= r < /// abs(rhs)`. + #[must_use] pub fn rem_euclid(self, rhs: Self) -> Self { let r = self % rhs; if r < Self::zero() { @@ -801,6 +818,7 @@ impl I256 { /// (where `MIN` is the negative minimal value for the type). /// This is equivalent to `-MIN`, a positive value that is too large to represent in the type. /// In this case, this method returns `MIN` itself. + #[must_use] pub fn wrapping_div_euclid(self, rhs: Self) -> Self { self.overflowing_div_euclid(rhs).0 } @@ -823,6 +841,7 @@ impl I256 { /// (where `MIN` is the negative minimal value for the type). /// In this case, this method returns `0`. /// Panics when `rhs == 0` + #[must_use] pub fn wrapping_rem_euclid(self, rhs: Self) -> Self { self.overflowing_rem_euclid(rhs).0 } @@ -867,6 +886,7 @@ impl I256 { /// # Panics /// /// Panics if the result overflows the type in debug mode. + #[must_use] pub fn pow(self, exp: u32) -> Self { handle_overflow(self.overflowing_pow(exp)) } @@ -895,6 +915,7 @@ impl I256 { /// Raises self to the power of `exp`, saturating at the numeric bounds /// instead of overflowing. + #[must_use] pub fn saturating_pow(self, exp: u32) -> Self { let (result, overflow) = self.overflowing_pow(exp); if overflow { @@ -909,6 +930,7 @@ impl I256 { /// Wrapping powolute value. Computes `self.pow()`, wrapping around at the /// boundary of the type. + #[must_use] pub fn wrapping_pow(self, exp: u32) -> Self { let (result, _) = self.overflowing_pow(exp); result @@ -1635,7 +1657,7 @@ mod tests { #[test] #[cfg_attr(debug_assertions, should_panic)] fn div_euclid_overflow() { - I256::MIN.div_euclid(-I256::one()); + let _ = I256::MIN.div_euclid(-I256::one()); } #[test] diff --git a/ethers-core/src/types/log.rs b/ethers-core/src/types/log.rs index 43552ca4..374765ab 100644 --- a/ethers-core/src/types/log.rs +++ b/ethers-core/src/types/log.rs @@ -123,6 +123,7 @@ impl Default for FilterBlockOption { } impl FilterBlockOption { + #[must_use] pub fn set_from_block(&self, block: BlockNumber) -> Self { let to_block = if let FilterBlockOption::Range { to_block, .. } = self { *to_block } else { None }; @@ -130,6 +131,7 @@ impl FilterBlockOption { FilterBlockOption::Range { from_block: Some(block), to_block } } + #[must_use] pub fn set_to_block(&self, block: BlockNumber) -> Self { let from_block = if let FilterBlockOption::Range { from_block, .. } = self { *from_block } else { None }; @@ -137,6 +139,7 @@ impl FilterBlockOption { FilterBlockOption::Range { from_block, to_block: Some(block) } } + #[must_use] pub fn set_hash(&self, hash: H256) -> Self { FilterBlockOption::AtBlockHash(hash) } @@ -273,64 +276,75 @@ impl Filter { /// let filter = Filter::new().select(..1337u64); /// # } /// ``` + #[must_use] pub fn select(mut self, filter: impl Into) -> Self { self.block_option = filter.into(); self } #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn from_block>(mut self, block: T) -> Self { self.block_option = self.block_option.set_from_block(block.into()); self } #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn to_block>(mut self, block: T) -> Self { self.block_option = self.block_option.set_to_block(block.into()); self } #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn at_block_hash>(mut self, hash: T) -> Self { self.block_option = self.block_option.set_hash(hash.into()); self } + #[must_use] pub fn address>>(mut self, address: T) -> Self { self.address = Some(address.into()); self } /// given the event in string form, it hashes it and adds it to the topics to monitor + #[must_use] pub fn event(self, event_name: &str) -> Self { let hash = H256::from(keccak256(event_name.as_bytes())); self.topic0(hash) } /// Sets topic0 (the event name for non-anonymous events) + #[must_use] pub fn topic0>>(mut self, topic: T) -> Self { self.topics[0] = Some(topic.into()); self } /// Sets the 1st indexed topic + #[must_use] pub fn topic1>>(mut self, topic: T) -> Self { self.topics[1] = Some(topic.into()); self } /// Sets the 2nd indexed topic + #[must_use] pub fn topic2>>(mut self, topic: T) -> Self { self.topics[2] = Some(topic.into()); self } /// Sets the 3rd indexed topic + #[must_use] pub fn topic3>>(mut self, topic: T) -> Self { self.topics[3] = Some(topic.into()); self } + #[must_use] pub fn limit(mut self, limit: usize) -> Self { self.limit = Some(limit); self diff --git a/ethers-core/src/types/trace/filter.rs b/ethers-core/src/types/trace/filter.rs index 7424e74d..c69cb2cd 100644 --- a/ethers-core/src/types/trace/filter.rs +++ b/ethers-core/src/types/trace/filter.rs @@ -29,6 +29,7 @@ pub struct TraceFilter { impl TraceFilter { /// Sets From block #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn from_block>(mut self, block: T) -> Self { self.from_block = Some(block.into()); self @@ -36,6 +37,7 @@ impl TraceFilter { /// Sets to block #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn to_block>(mut self, block: T) -> Self { self.to_block = Some(block.into()); self @@ -43,6 +45,7 @@ impl TraceFilter { /// Sets to address #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn to_address(mut self, address: Vec) -> Self { self.to_address = Some(address); self @@ -50,18 +53,21 @@ impl TraceFilter { /// Sets from address #[allow(clippy::wrong_self_convention)] + #[must_use] pub fn from_address(mut self, address: Vec) -> Self { self.from_address = Some(address); self } /// Sets after offset + #[must_use] pub fn after(mut self, after: usize) -> Self { self.after = Some(after); self } /// Sets amount of traces to display + #[must_use] pub fn count(mut self, count: usize) -> Self { self.count = Some(count); self diff --git a/ethers-core/src/types/transaction/eip1559.rs b/ethers-core/src/types/transaction/eip1559.rs index ced1e1c3..2868be31 100644 --- a/ethers-core/src/types/transaction/eip1559.rs +++ b/ethers-core/src/types/transaction/eip1559.rs @@ -68,54 +68,63 @@ impl Eip1559TransactionRequest { // Builder pattern helpers /// Sets the `from` field in the transaction to the provided value + #[must_use] pub fn from>(mut self, from: T) -> Self { self.from = Some(from.into()); self } /// Sets the `to` field in the transaction to the provided value + #[must_use] pub fn to>(mut self, to: T) -> Self { self.to = Some(to.into()); self } /// Sets the `gas` field in the transaction to the provided value + #[must_use] pub fn gas>(mut self, gas: T) -> Self { self.gas = Some(gas.into()); self } /// Sets the `max_priority_fee_per_gas` field in the transaction to the provided value + #[must_use] pub fn max_priority_fee_per_gas>(mut self, max_priority_fee_per_gas: T) -> Self { self.max_priority_fee_per_gas = Some(max_priority_fee_per_gas.into()); self } /// Sets the `max_fee_per_gas` field in the transaction to the provided value + #[must_use] pub fn max_fee_per_gas>(mut self, max_fee_per_gas: T) -> Self { self.max_fee_per_gas = Some(max_fee_per_gas.into()); self } /// Sets the `value` field in the transaction to the provided value + #[must_use] pub fn value>(mut self, value: T) -> Self { self.value = Some(value.into()); self } /// Sets the `data` field in the transaction to the provided value + #[must_use] pub fn data>(mut self, data: T) -> Self { self.data = Some(data.into()); self } /// Sets the `access_list` field in the transaction to the provided value + #[must_use] pub fn access_list>(mut self, access_list: T) -> Self { self.access_list = access_list.into(); self } /// Sets the `nonce` field in the transaction to the provided value + #[must_use] pub fn nonce>(mut self, nonce: T) -> Self { self.nonce = Some(nonce.into()); self diff --git a/ethers-core/src/types/transaction/eip2930.rs b/ethers-core/src/types/transaction/eip2930.rs index b40670e0..c9b6fb4e 100644 --- a/ethers-core/src/types/transaction/eip2930.rs +++ b/ethers-core/src/types/transaction/eip2930.rs @@ -119,7 +119,7 @@ mod tests { let enc = rlp::encode(&tx.rlp_signed(1, &sig).as_ref()); let expected = "b86601f8630103018261a894b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a825544c001a0c9519f4f2b30335884581971573fadf60c6204f59a911df35ee8a540456b2660a032f1e8e2c5dd761f9e4f88f41c8310aeaba26a8bfcdacfedfa12ec3862d37521"; - assert_eq!(hex::encode(enc.to_vec()), expected); + assert_eq!(hex::encode(&enc), expected); } #[test] diff --git a/ethers-core/src/types/transaction/eip712.rs b/ethers-core/src/types/transaction/eip712.rs index d7cd3a44..61a6b9a1 100644 --- a/ethers-core/src/types/transaction/eip712.rs +++ b/ethers-core/src/types/transaction/eip712.rs @@ -166,6 +166,7 @@ impl EIP712WithDomain { Ok(Self { domain, inner }) } + #[must_use] pub fn set_domain(self, domain: EIP712Domain) -> Self { Self { domain, inner: self.inner } } diff --git a/ethers-core/src/types/transaction/request.rs b/ethers-core/src/types/transaction/request.rs index 065eccf9..371b120f 100644 --- a/ethers-core/src/types/transaction/request.rs +++ b/ethers-core/src/types/transaction/request.rs @@ -75,42 +75,49 @@ impl TransactionRequest { // Builder pattern helpers /// Sets the `from` field in the transaction to the provided value + #[must_use] pub fn from>(mut self, from: T) -> Self { self.from = Some(from.into()); self } /// Sets the `to` field in the transaction to the provided value + #[must_use] pub fn to>(mut self, to: T) -> Self { self.to = Some(to.into()); self } /// Sets the `gas` field in the transaction to the provided value + #[must_use] pub fn gas>(mut self, gas: T) -> Self { self.gas = Some(gas.into()); self } /// Sets the `gas_price` field in the transaction to the provided value + #[must_use] pub fn gas_price>(mut self, gas_price: T) -> Self { self.gas_price = Some(gas_price.into()); self } /// Sets the `value` field in the transaction to the provided value + #[must_use] pub fn value>(mut self, value: T) -> Self { self.value = Some(value.into()); self } /// Sets the `data` field in the transaction to the provided value + #[must_use] pub fn data>(mut self, data: T) -> Self { self.data = Some(data.into()); self } /// Sets the `nonce` field in the transaction to the provided value + #[must_use] pub fn nonce>(mut self, nonce: T) -> Self { self.nonce = Some(nonce.into()); self @@ -174,6 +181,7 @@ impl TransactionRequest { /// Sets the `fee_currency` field in the transaction to the provided value #[cfg_attr(docsrs, doc(cfg(feature = "celo")))] + #[must_use] pub fn fee_currency>(mut self, fee_currency: T) -> Self { self.fee_currency = Some(fee_currency.into()); self @@ -181,6 +189,7 @@ impl TransactionRequest { /// Sets the `gateway_fee` field in the transaction to the provided value #[cfg_attr(docsrs, doc(cfg(feature = "celo")))] + #[must_use] pub fn gateway_fee>(mut self, gateway_fee: T) -> Self { self.gateway_fee = Some(gateway_fee.into()); self @@ -188,6 +197,7 @@ impl TransactionRequest { /// Sets the `gateway_fee_recipient` field in the transaction to the provided value #[cfg_attr(docsrs, doc(cfg(feature = "celo")))] + #[must_use] pub fn gateway_fee_recipient>(mut self, gateway_fee_recipient: T) -> Self { self.gateway_fee_recipient = Some(gateway_fee_recipient.into()); self diff --git a/ethers-core/src/utils/ganache.rs b/ethers-core/src/utils/ganache.rs index c68c1a58..c173a742 100644 --- a/ethers-core/src/utils/ganache.rs +++ b/ethers-core/src/utils/ganache.rs @@ -93,18 +93,21 @@ impl Ganache { } /// Sets the port which will be used when the `ganache-cli` instance is launched. + #[must_use] pub fn port>(mut self, port: T) -> Self { self.port = Some(port.into()); self } /// Sets the mnemonic which will be used when the `ganache-cli` instance is launched. + #[must_use] pub fn mnemonic>(mut self, mnemonic: T) -> Self { self.mnemonic = Some(mnemonic.into()); self } /// Sets the block-time which will be used when the `ganache-cli` instance is launched. + #[must_use] pub fn block_time>(mut self, block_time: T) -> Self { self.block_time = Some(block_time.into()); self @@ -114,18 +117,21 @@ impl Ganache { /// at a given block. Input should be the HTTP location and port of the other client, /// e.g. `http://localhost:8545`. You can optionally specify the block to fork from /// using an @ sign: `http://localhost:8545@1599200` + #[must_use] pub fn fork>(mut self, fork: T) -> Self { self.fork = Some(fork.into()); self } /// Adds an argument to pass to the `ganache-cli`. + #[must_use] pub fn arg>(mut self, arg: T) -> Self { self.args.push(arg.into()); self } /// Adds multiple arguments to pass to the `ganache-cli`. + #[must_use] pub fn args(mut self, args: I) -> Self where I: IntoIterator, diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index 22ded40b..9016bc8f 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -87,18 +87,21 @@ impl Geth { } /// Sets the port which will be used when the `geth-cli` instance is launched. + #[must_use] pub fn port>(mut self, port: T) -> Self { self.port = Some(port.into()); self } /// Sets the block-time which will be used when the `geth-cli` instance is launched. + #[must_use] pub fn block_time>(mut self, block_time: T) -> Self { self.block_time = Some(block_time.into()); self } /// Manually sets the IPC path for the socket manually. + #[must_use] pub fn ipc_path>(mut self, path: T) -> Self { self.ipc_path = Some(path.into()); self diff --git a/ethers-etherscan/src/contract.rs b/ethers-etherscan/src/contract.rs index 87ea0b03..45eab419 100644 --- a/ethers-etherscan/src/contract.rs +++ b/ethers-etherscan/src/contract.rs @@ -49,16 +49,19 @@ impl VerifyContract { } } + #[must_use] pub fn contract_name(mut self, name: impl Into) -> Self { self.contract_name = Some(name.into()); self } + #[must_use] pub fn runs(mut self, runs: u32) -> Self { self.runs = Some(format!("{}", runs)); self } + #[must_use] pub fn optimization(self, optimization: bool) -> Self { if optimization { self.optimized() @@ -67,26 +70,31 @@ impl VerifyContract { } } + #[must_use] pub fn optimized(mut self) -> Self { self.optimization_used = Some("1".to_string()); self } + #[must_use] pub fn not_optimized(mut self) -> Self { self.optimization_used = Some("0".to_string()); self } + #[must_use] pub fn code_format(mut self, code_format: CodeFormat) -> Self { self.code_format = code_format; self } + #[must_use] pub fn evm_version(mut self, evm_version: impl Into) -> Self { self.evm_version = Some(evm_version.into()); self } + #[must_use] pub fn constructor_arguments( mut self, constructor_arguments: Option>, diff --git a/ethers-middleware/src/gas_oracle/eth_gas_station.rs b/ethers-middleware/src/gas_oracle/eth_gas_station.rs index 1c430948..6e2510c5 100644 --- a/ethers-middleware/src/gas_oracle/eth_gas_station.rs +++ b/ethers-middleware/src/gas_oracle/eth_gas_station.rs @@ -73,6 +73,7 @@ impl EthGasStation { } /// Sets the gas price category to be used when fetching the gas price. + #[must_use] pub fn category(mut self, gas_category: GasCategory) -> Self { self.gas_category = gas_category; self diff --git a/ethers-middleware/src/gas_oracle/etherchain.rs b/ethers-middleware/src/gas_oracle/etherchain.rs index 551269ef..f74187a8 100644 --- a/ethers-middleware/src/gas_oracle/etherchain.rs +++ b/ethers-middleware/src/gas_oracle/etherchain.rs @@ -44,6 +44,7 @@ impl Etherchain { } /// Sets the gas price category to be used when fetching the gas price. + #[must_use] pub fn category(mut self, gas_category: GasCategory) -> Self { self.gas_category = gas_category; self diff --git a/ethers-middleware/src/gas_oracle/etherscan.rs b/ethers-middleware/src/gas_oracle/etherscan.rs index 828f5f92..b39cebff 100644 --- a/ethers-middleware/src/gas_oracle/etherscan.rs +++ b/ethers-middleware/src/gas_oracle/etherscan.rs @@ -20,6 +20,7 @@ impl Etherscan { } /// Sets the gas price category to be used when fetching the gas price. + #[must_use] pub fn category(mut self, gas_category: GasCategory) -> Self { self.gas_category = gas_category; self diff --git a/ethers-middleware/src/signer.rs b/ethers-middleware/src/signer.rs index 1d7c4be4..7234e94f 100644 --- a/ethers-middleware/src/signer.rs +++ b/ethers-middleware/src/signer.rs @@ -130,6 +130,7 @@ where &self.signer } + #[must_use] pub fn with_signer(&self, signer: S) -> Self where S: Clone, diff --git a/ethers-providers/src/pending_escalator.rs b/ethers-providers/src/pending_escalator.rs index 511fca36..b813f986 100644 --- a/ethers-providers/src/pending_escalator.rs +++ b/ethers-providers/src/pending_escalator.rs @@ -1,3 +1,5 @@ +#![allow(clippy::return_self_not_must_use)] + use ethers_core::types::{Bytes, TransactionReceipt, H256}; use futures_util::{stream::FuturesUnordered, StreamExt}; use pin_project::pin_project; diff --git a/ethers-providers/src/pending_transaction.rs b/ethers-providers/src/pending_transaction.rs index fbb070e8..968f689b 100644 --- a/ethers-providers/src/pending_transaction.rs +++ b/ethers-providers/src/pending_transaction.rs @@ -57,12 +57,14 @@ impl<'a, P: JsonRpcClient> PendingTransaction<'a, P> { /// Sets the number of confirmations for the pending transaction to resolve /// to a receipt + #[must_use] pub fn confirmations(mut self, confs: usize) -> Self { self.confirmations = confs; self } /// Sets the polling interval + #[must_use] pub fn interval>(mut self, duration: T) -> Self { let duration = duration.into(); diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index e0ebdeb4..8d2617cb 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -175,6 +175,7 @@ impl Provider

{ } } + #[must_use] pub fn with_sender(mut self, address: impl Into

) -> Self { self.from = Some(address.into()); self @@ -973,6 +974,7 @@ impl Provider

{ } /// Sets the ENS Address (default: mainnet) + #[must_use] pub fn ens>(mut self, ens: T) -> Self { self.ens = Some(ens.into()); self @@ -980,6 +982,7 @@ impl Provider

{ /// Sets the default polling interval for event filters and pending transactions /// (default: 7 seconds) + #[must_use] pub fn interval>(mut self, interval: T) -> Self { self.interval = Some(interval.into()); self diff --git a/ethers-providers/src/stream.rs b/ethers-providers/src/stream.rs index b8ebe181..4003b61c 100644 --- a/ethers-providers/src/stream.rs +++ b/ethers-providers/src/stream.rs @@ -1,3 +1,5 @@ +#![allow(clippy::return_self_not_must_use)] + use crate::{JsonRpcClient, Middleware, PinBoxFut, Provider, ProviderError}; use ethers_core::types::{Transaction, TxHash, U256}; diff --git a/ethers-signers/src/lib.rs b/ethers-signers/src/lib.rs index f127fa30..86888911 100644 --- a/ethers-signers/src/lib.rs +++ b/ethers-signers/src/lib.rs @@ -79,5 +79,6 @@ pub trait Signer: std::fmt::Debug + Send + Sync { fn chain_id(&self) -> u64; /// Sets the signer's chain id + #[must_use] fn with_chain_id>(self, chain_id: T) -> Self; } diff --git a/ethers-signers/src/trezor/app.rs b/ethers-signers/src/trezor/app.rs index 8434857e..74768090 100644 --- a/ethers-signers/src/trezor/app.rs +++ b/ethers-signers/src/trezor/app.rs @@ -249,7 +249,7 @@ mod tests { let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap(); // invalid data - let big_data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string()+ &"ff".repeat(1032*2) + &"aa".to_string()).unwrap(); + let big_data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string()+ &"ff".repeat(1032*2) + "aa").unwrap(); let tx_req = TransactionRequest::new() .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::

().unwrap()) .gas(1000000) diff --git a/ethers-signers/src/wallet/mnemonic.rs b/ethers-signers/src/wallet/mnemonic.rs index c3377c0e..38c6a19b 100644 --- a/ethers-signers/src/wallet/mnemonic.rs +++ b/ethers-signers/src/wallet/mnemonic.rs @@ -82,6 +82,7 @@ impl MnemonicBuilder { /// # Ok(()) /// # } /// ``` + #[must_use] pub fn phrase>(mut self, phrase: P) -> Self { self.phrase = Some(phrase.into()); self @@ -104,6 +105,7 @@ impl MnemonicBuilder { /// # Ok(()) /// # } /// ``` + #[must_use] pub fn word_count(mut self, count: usize) -> Self { self.word_count = count; self @@ -127,6 +129,7 @@ impl MnemonicBuilder { } /// Sets the password used to construct the seed from the mnemonic phrase. + #[must_use] pub fn password(mut self, password: &str) -> Self { self.password = Some(password.to_string()); self @@ -134,6 +137,7 @@ impl MnemonicBuilder { /// Sets the path to which the randomly generated phrase will be written to. This field is /// ignored when building a wallet from the provided mnemonic phrase. + #[must_use] pub fn write_to>(mut self, path: P) -> Self { self.write_to = Some(path.into()); self diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index 20719dcc..3ba04a3b 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -40,12 +40,14 @@ impl CompilerInput { } /// Sets the EVM version for compilation + #[must_use] pub fn evm_version(mut self, version: EvmVersion) -> Self { self.settings.evm_version = Some(version); self } /// Sets the optimizer runs (default = 200) + #[must_use] pub fn optimizer(mut self, runs: usize) -> Self { self.settings.optimizer.runs(runs); self @@ -53,6 +55,7 @@ impl CompilerInput { /// Normalizes the EVM version used in the settings to be up to the latest one /// supported by the provided compiler version. + #[must_use] pub fn normalize_evm_version(mut self, version: &Version) -> Self { if let Some(ref mut evm_version) = self.settings.evm_version { self.settings.evm_version = evm_version.normalize_version(version); @@ -60,6 +63,7 @@ impl CompilerInput { self } + #[must_use] pub fn with_remappings(mut self, remappings: Vec) -> Self { self.settings.remappings = remappings; self @@ -172,6 +176,7 @@ impl Settings { } /// Adds `ast` to output + #[must_use] pub fn with_ast(mut self) -> Self { let output = self.output_selection.entry("*".to_string()).or_insert_with(BTreeMap::default); output.insert("".to_string(), vec!["ast".to_string()]); diff --git a/ethers-solc/src/cache.rs b/ethers-solc/src/cache.rs index fcf13ad3..3ca2b26a 100644 --- a/ethers-solc/src/cache.rs +++ b/ethers-solc/src/cache.rs @@ -219,16 +219,19 @@ pub struct SolFilesCacheBuilder { } impl SolFilesCacheBuilder { + #[must_use] pub fn format(mut self, format: impl Into) -> Self { self.format = Some(format.into()); self } + #[must_use] pub fn solc_config(mut self, solc_config: SolcConfig) -> Self { self.solc_config = Some(solc_config); self } + #[must_use] pub fn root(mut self, root: impl Into) -> Self { self.root = Some(root.into()); self diff --git a/ethers-solc/src/compile.rs b/ethers-solc/src/compile.rs index 0521bee0..fb1d30b4 100644 --- a/ethers-solc/src/compile.rs +++ b/ethers-solc/src/compile.rs @@ -88,12 +88,14 @@ impl Solc { } /// Adds an argument to pass to the `solc` command. + #[must_use] pub fn arg>(mut self, arg: T) -> Self { self.args.push(arg.into()); self } /// Adds multiple arguments to pass to the `solc`. + #[must_use] pub fn args(mut self, args: I) -> Self where I: IntoIterator, diff --git a/ethers-solc/src/lib.rs b/ethers-solc/src/lib.rs index 21b0edcd..91c3049d 100644 --- a/ethers-solc/src/lib.rs +++ b/ethers-solc/src/lib.rs @@ -529,39 +529,46 @@ pub struct ProjectBuilder } impl ProjectBuilder { + #[must_use] pub fn paths(mut self, paths: ProjectPathsConfig) -> Self { self.paths = Some(paths); self } + #[must_use] pub fn solc(mut self, solc: impl Into) -> Self { self.solc = Some(solc.into()); self } + #[must_use] pub fn solc_config(mut self, solc_config: SolcConfig) -> Self { self.solc_config = Some(solc_config); self } + #[must_use] pub fn ignore_error_code(mut self, code: u64) -> Self { self.ignored_error_codes.push(code); self } /// Disables cached builds + #[must_use] pub fn ephemeral(mut self) -> Self { self.cached = false; self } /// Disables writing artifacts to disk + #[must_use] pub fn no_artifacts(mut self) -> Self { self.no_artifacts = true; self } /// Disables automatic solc version detection + #[must_use] pub fn no_auto_detect(mut self) -> Self { self.auto_detect = false; self @@ -572,6 +579,7 @@ impl ProjectBuilder { /// # Panics /// /// `jobs` must be at least 1 + #[must_use] pub fn solc_jobs(mut self, jobs: usize) -> Self { assert!(jobs > 0); self.solc_jobs = Some(jobs); @@ -579,6 +587,7 @@ impl ProjectBuilder { } /// Sets the number of parallel `solc` processes to `1`, no parallelization + #[must_use] pub fn single_solc_jobs(self) -> Self { self.solc_jobs(1) } @@ -612,12 +621,14 @@ impl ProjectBuilder { } /// Adds an allowed-path to the solc executable + #[must_use] pub fn allowed_path>(mut self, path: T) -> Self { self.allowed_paths.push(path.into()); self } /// Adds multiple allowed-path to the solc executable + #[must_use] pub fn allowed_paths(mut self, args: I) -> Self where I: IntoIterator,