Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

chore(clippy): make clippy happy #705

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ethers-contract/ethers-contract-abigen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S1, S2>(mut self, signature: S1, alias: S2) -> Self
where
S1: Into<String>,
Expand All @@ -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<S1, S2>(mut self, signature: S1, alias: S2) -> Self
where
S1: Into<String>,
Expand All @@ -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
Expand All @@ -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<S>(mut self, derive: S) -> Self
where
S: Into<String>,
Expand Down
2 changes: 2 additions & 0 deletions ethers-contract/src/call.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
2 changes: 2 additions & 0 deletions ethers-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl<M: Middleware> Contract<M> {
/// Returns a new contract instance at `address`.
///
/// Clones `self` internally
#[must_use]
pub fn at<T: Into<Address>>(&self, address: T) -> Self
where
M: Clone,
Expand All @@ -259,6 +260,7 @@ impl<M: Middleware> Contract<M> {
/// Returns a new contract instance using the provided client
///
/// Clones `self` internally
#[must_use]
pub fn connect(&self, client: Arc<M>) -> Self
where
M: Clone,
Expand Down
2 changes: 2 additions & 0 deletions ethers-contract/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::return_self_not_must_use)]

use crate::{log::LogMeta, stream::EventStream, ContractError, EthLogDecode};

use ethers_core::{
Expand Down
3 changes: 3 additions & 0 deletions ethers-contract/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ pub struct Deployer<M> {

impl<M: Middleware> Deployer<M> {
/// Sets the number of confirmations to wait for the contract deployment transaction
#[must_use]
pub fn confirmations<T: Into<usize>>(mut self, confirmations: T) -> Self {
self.confs = confirmations.into();
self
}

#[must_use]
pub fn block<T: Into<BlockNumber>>(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) => {
Expand Down
2 changes: 2 additions & 0 deletions ethers-contract/src/multicall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ impl<M: Middleware> Multicall<M> {
}

/// 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<T: Into<BlockNumber>>(mut self, block: T) -> Self {
self.block = Some(block.into());
self
Expand Down
24 changes: 23 additions & 1 deletion ethers-core/src/types/i256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl I256 {
}

/// Returns the sign of the number.
#[must_use]
pub fn signum(self) -> Self {
self.signum64().into()
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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()) {
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions ethers-core/src/types/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,23 @@ 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 };

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 };

FilterBlockOption::Range { from_block, to_block: Some(block) }
}

#[must_use]
pub fn set_hash(&self, hash: H256) -> Self {
FilterBlockOption::AtBlockHash(hash)
}
Expand Down Expand Up @@ -273,64 +276,75 @@ impl Filter {
/// let filter = Filter::new().select(..1337u64);
/// # }
/// ```
#[must_use]
pub fn select(mut self, filter: impl Into<FilterBlockOption>) -> Self {
self.block_option = filter.into();
self
}

#[allow(clippy::wrong_self_convention)]
#[must_use]
pub fn from_block<T: Into<BlockNumber>>(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<T: Into<BlockNumber>>(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<T: Into<H256>>(mut self, hash: T) -> Self {
self.block_option = self.block_option.set_hash(hash.into());
self
}

#[must_use]
pub fn address<T: Into<ValueOrArray<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<T: Into<ValueOrArray<H256>>>(mut self, topic: T) -> Self {
self.topics[0] = Some(topic.into());
self
}

/// Sets the 1st indexed topic
#[must_use]
pub fn topic1<T: Into<ValueOrArray<H256>>>(mut self, topic: T) -> Self {
self.topics[1] = Some(topic.into());
self
}

/// Sets the 2nd indexed topic
#[must_use]
pub fn topic2<T: Into<ValueOrArray<H256>>>(mut self, topic: T) -> Self {
self.topics[2] = Some(topic.into());
self
}

/// Sets the 3rd indexed topic
#[must_use]
pub fn topic3<T: Into<ValueOrArray<H256>>>(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
Expand Down
Loading