Repository: gakonst/ethers-rs
Pull request #1525 (2022-07-28 12:27:02)

chore(clippy): make clippy happy
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

## Motivation
fix some clippy things
<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

## PR Checklist

- [ ] Added Tests
- [ ] Added Documentation
- [ ] Updated the changelog



Patch:
diff --git a/ethers-contract/ethers-contract-abigen/src/contract/events.rs b/ethers-contract/ethers-contract-abigen/src/contract/events.rs
index d7fb7b5e..9c098635 100644
--- a/ethers-contract/ethers-contract-abigen/src/contract/events.rs
+++ b/ethers-contract/ethers-contract-abigen/src/contract/events.rs
@@ -77,7 +77,7 @@ impl Context {
             }
 
              impl #ethers_contract::EthLogDecode for #enum_name {
-                fn decode_log(log: &#ethers_core::abi::RawLog) -> Result<Self, #ethers_core::abi::Error>
+                fn decode_log(log: &#ethers_core::abi::RawLog) -> ::std::result::Result<Self, #ethers_core::abi::Error>
                 where
                     Self: Sized,
                 {
diff --git a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
index 912444c7..3894802b 100644
--- a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
+++ b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs
@@ -91,7 +91,7 @@ impl Context {
             ///    let msg = greeter_contract.greet().call().await.unwrap();
             /// # }
             /// ```
-            pub fn deploy<T: #ethers_core::abi::Tokenize >(client: ::std::sync::Arc<M>, constructor_args: T) -> Result<#ethers_contract::builders::ContractDeployer<M, Self>, #ethers_contract::ContractError<M>> {
+            pub fn deploy<T: #ethers_core::abi::Tokenize >(client: ::std::sync::Arc<M>, constructor_args: T) -> ::std::result::Result<#ethers_contract::builders::ContractDeployer<M, Self>, #ethers_contract::ContractError<M>> {
                let factory = #ethers_contract::ContractFactory::new(#get_abi, #get_bytecode, client);
                let deployer = factory.deploy(constructor_args)?;
                let deployer = #ethers_contract::ContractDeployer::new(deployer);
@@ -219,7 +219,7 @@ impl Context {
             }
 
         impl  #ethers_core::abi::AbiDecode for #enum_name {
-            fn decode(data: impl AsRef<[u8]>) -> Result<Self, #ethers_core::abi::AbiError> {
+            fn decode(data: impl AsRef<[u8]>) -> ::std::result::Result<Self, #ethers_core::abi::AbiError> {
                  #(
                     if let Ok(decoded) = <#struct_names as #ethers_core::abi::AbiDecode>::decode(data.as_ref()) {
                         return Ok(#enum_name::#variant_names(decoded))
diff --git a/ethers-contract/ethers-contract-derive/src/abi_ty.rs b/ethers-contract/ethers-contract-derive/src/abi_ty.rs
index 18b43669..442d9d1d 100644
--- a/ethers-contract/ethers-contract-derive/src/abi_ty.rs
+++ b/ethers-contract/ethers-contract-derive/src/abi_ty.rs
@@ -152,7 +152,7 @@ pub fn derive_tokenizeable_impl(input: &DeriveInput) -> proc_macro2::TokenStream
              #tokenize_predicates
          {
 
-             fn from_token(token: #core_crate::abi::Token) -> Result<Self, #core_crate::abi::InvalidOutputType> where
+             fn from_token(token: #core_crate::abi::Token) -> ::std::result::Result<Self, #core_crate::abi::InvalidOutputType> where
                  Self: Sized {
                 #from_token_impl
              }
@@ -174,7 +174,7 @@ fn tokenize_unit_type(name: &Ident) -> TokenStream {
     let ethers_core = ethers_core_crate();
     quote! {
          impl #ethers_core::abi::Tokenizable for #name {
-             fn from_token(token: #ethers_core::abi::Token) -> Result<Self, #ethers_core::abi::InvalidOutputType> where
+             fn from_token(token: #ethers_core::abi::Token) -> ::std::result::Result<Self, #ethers_core::abi::InvalidOutputType> where
                  Self: Sized {
                 if let #ethers_core::abi::Token::Tuple(tokens) = token {
                     if !tokens.is_empty() {
@@ -210,7 +210,7 @@ fn tokenize_unit_type(name: &Ident) -> TokenStream {
 fn tokenize_enum<'a>(
     enum_name: &Ident,
     variants: impl Iterator<Item = &'a Variant> + 'a,
-) -> Result<TokenStream, Error> {
+) -> ::std::result::Result<TokenStream, Error> {
     let ethers_core = ethers_core_crate();
 
     let mut into_tokens = TokenStream::new();
@@ -252,7 +252,7 @@ fn tokenize_enum<'a>(
     Ok(quote! {
          impl #ethers_core::abi::Tokenizable for #enum_name {
 
-             fn from_token(token: #ethers_core::abi::Token) -> Result<Self, #ethers_core::abi::InvalidOutputType> where
+             fn from_token(token: #ethers_core::abi::Token) -> ::std::result::Result<Self, #ethers_core::abi::InvalidOutputType> where
                  Self: Sized {
                 #from_tokens
                 Err(#ethers_core::abi::InvalidOutputType("Failed to decode all type variants".to_string()))
diff --git a/ethers-contract/ethers-contract-derive/src/abigen.rs b/ethers-contract/ethers-contract-derive/src/abigen.rs
index f1c47e3b..a91334ed 100644
--- a/ethers-contract/ethers-contract-derive/src/abigen.rs
+++ b/ethers-contract/ethers-contract-derive/src/abigen.rs
@@ -27,7 +27,7 @@ pub(crate) struct Contracts {
 }
 
 impl Contracts {
-    pub(crate) fn expand(self) -> Result<TokenStream2, syn::Error> {
+    pub(crate) fn expand(self) -> ::std::result::Result<TokenStream2, syn::Error> {
         let mut expansions = Vec::with_capacity(self.inner.len());
 
         // expand all contracts
diff --git a/ethers-contract/ethers-contract-derive/src/call.rs b/ethers-contract/ethers-contract-derive/src/call.rs
index 15f901a0..f86163ed 100644
--- a/ethers-contract/ethers-contract-derive/src/call.rs
+++ b/ethers-contract/ethers-contract-derive/src/call.rs
@@ -95,7 +95,7 @@ pub fn derive_trait_impls(
         }
 
         impl  #core_crate::abi::AbiDecode for #struct_name {
-            fn decode(bytes: impl AsRef<[u8]>) -> Result<Self, #core_crate::abi::AbiError> {
+            fn decode(bytes: impl AsRef<[u8]>) -> ::std::result::Result<Self, #core_crate::abi::AbiError> {
                 #decode_impl
             }
         }
diff --git a/ethers-contract/ethers-contract-derive/src/codec.rs b/ethers-contract/ethers-contract-derive/src/codec.rs
index 54a577f2..15472fc2 100644
--- a/ethers-contract/ethers-contract-derive/src/codec.rs
+++ b/ethers-contract/ethers-contract-derive/src/codec.rs
@@ -12,7 +12,7 @@ pub fn derive_codec_impl(input: &DeriveInput) -> proc_macro2::TokenStream {
 
     quote! {
         impl  #core_crate::abi::AbiDecode for #name {
-            fn decode(bytes: impl AsRef<[u8]>) -> Result<Self, #core_crate::abi::AbiError> {
+            fn decode(bytes: impl AsRef<[u8]>) -> ::std::result::Result<Self, #core_crate::abi::AbiError> {
                 if let #core_crate::abi::ParamType::Tuple(params) = <Self as #core_crate::abi::AbiType>::param_type() {
                   let tokens = #core_crate::abi::decode(&params, bytes.as_ref())?;
                   Ok(<Self as #core_crate::abi::Tokenizable>::from_token(#core_crate::abi::Token::Tuple(tokens))?)
diff --git a/ethers-contract/ethers-contract-derive/src/event.rs b/ethers-contract/ethers-contract-derive/src/event.rs
index 05d02f4f..0e56314f 100644
--- a/ethers-contract/ethers-contract-derive/src/event.rs
+++ b/ethers-contract/ethers-contract-derive/src/event.rs
@@ -95,7 +95,7 @@ pub(crate) fn derive_eth_event_impl(input: DeriveInput) -> TokenStream {
                 #abi.into()
             }
 
-            fn decode_log(log: &#core_crate::abi::RawLog) -> Result<Self, #core_crate::abi::Error> where Self: Sized {
+            fn decode_log(log: &#core_crate::abi::RawLog) -> ::std::result::Result<Self, #core_crate::abi::Error> where Self: Sized {
                 #decode_log_impl
             }
 
diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs
index ce0d4e28..03a2dc33 100644
--- a/ethers-core/src/types/block.rs
+++ b/ethers-core/src/types/block.rs
@@ -764,11 +764,13 @@ mod tests {
     #[test]
     fn test_next_block_base_fee() {
         // <https://etherscan.io/block/14402566>
-        let mut block_14402566 = Block::<TxHash>::default();
-        block_14402566.number = Some(U64::from(14402566u64));
-        block_14402566.base_fee_per_gas = Some(U256::from(36_803_013_756u128));
-        block_14402566.gas_limit = U256::from(30_087_887u128);
-        block_14402566.gas_used = U256::from(2_023_848u128);
+        let block_14402566: Block<TxHash> = Block {
+            number: Some(U64::from(14402566u64)),
+            base_fee_per_gas: Some(U256::from(36_803_013_756u128)),
+            gas_limit: U256::from(30_087_887u128),
+            gas_used: U256::from(2_023_848u128),
+            ..Default::default()
+        };
 
         assert_eq!(block_14402566.base_fee_per_gas, Some(U256::from(36_803_013_756u128)));
         assert_eq!(block_14402566.gas_target(), U256::from(15_043_943u128));
@@ -776,11 +778,13 @@ mod tests {
         assert_eq!(block_14402566.next_block_base_fee(), Some(U256::from(32_821_521_542u128)));
 
         // https://etherscan.io/block/14402712
-        let mut block_14402712 = Block::<TxHash>::default();
-        block_14402712.number = Some(U64::from(14402712u64));
-        block_14402712.base_fee_per_gas = Some(U256::from(24_870_031_149u128));
-        block_14402712.gas_limit = U256::from(30_000_000u128);
-        block_14402712.gas_used = U256::from(29_999_374u128);
+        let block_14402712: Block<TxHash> = Block {
+            number: Some(U64::from(14402712u64)),
+            base_fee_per_gas: Some(U256::from(24_870_031_149u128)),
+            gas_limit: U256::from(30_000_000u128),
+            gas_used: U256::from(29_999_374u128),
+            ..Default::default()
+        };
 
         assert_eq!(block_14402712.base_fee_per_gas, Some(U256::from(24_870_031_149u128)));
         assert_eq!(block_14402712.gas_target(), U256::from(15_000_000u128));
diff --git a/ethers-core/src/types/transaction/request.rs b/ethers-core/src/types/transaction/request.rs
index 25270d92..34a47f86 100644
--- a/ethers-core/src/types/transaction/request.rs
+++ b/ethers-core/src/types/transaction/request.rs
@@ -547,7 +547,7 @@ mod tests {
 
         let addresses = raw_addresses
             .iter()
-            .map(|addr| NameOrAddress::Address(Address::from_str(*addr).unwrap()));
+            .map(|addr| NameOrAddress::Address(Address::from_str(addr).unwrap()));
 
         // decoding will do sender recovery and we don't expect any of these to error, so we should
         // check that the address matches for each decoded transaction


Test patch:
diff --git a/ethers-contract/tests/it/common/derive.rs b/ethers-contract/tests/it/common/derive.rs
index d856cbb5..3198cc9e 100644
--- a/ethers-contract/tests/it/common/derive.rs
+++ b/ethers-contract/tests/it/common/derive.rs
@@ -605,3 +605,16 @@ fn eth_display_works_on_ethers_bytes() {
     let s = format!("{}", call);
     assert_eq!(s, "0xaaaaaa");
 }
+
+#[test]
+fn can_use_result_name() {
+    abigen!(
+        ResultContract,
+        r#"[
+           struct Result {uint256 result;}
+           result(Result result) (uint256)
+        ]"#,
+    );
+
+    let _call = ResultCall { result: Result { result: U256::zero() } };
+}