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

chore: clippy #1812

Merged
merged 2 commits into from
Nov 7, 2022
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
2 changes: 1 addition & 1 deletion ethers-contract/ethers-contract-abigen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ where
if not_aliased.len() > 1 {
let mut overloaded_aliases = Vec::new();
for (idx, (sig, name)) in not_aliased.into_iter().enumerate() {
let unique_name = format!("{}{}", name, idx + 1);
let unique_name = format!("{name}{}", idx + 1);
overloaded_aliases.push((sig, get_ident(&unique_name)));
}
aliases.extend(overloaded_aliases);
Expand Down
4 changes: 2 additions & 2 deletions ethers-contract/ethers-contract-abigen/src/contract/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
}

pub(crate) fn imports(name: &str) -> TokenStream {
let doc = util::expand_doc(&format!("{} was auto-generated with ethers-rs Abigen. More information at: https://github.com/gakonst/ethers-rs", name));
let doc = util::expand_doc(&format!("{name} was auto-generated with ethers-rs Abigen. More information at: https://github.com/gakonst/ethers-rs"));

let ethers_core = ethers_core_crate();
let ethers_providers = ethers_providers_crate();
Expand Down Expand Up @@ -116,7 +116,7 @@ pub(crate) fn struct_declaration(cx: &Context) -> TokenStream {

let bytecode = if let Some(ref bytecode) = cx.contract_bytecode {
let bytecode_name = cx.inline_bytecode_ident();
let hex_bytecode = format!("{}", bytecode);
let hex_bytecode = format!("{bytecode}");
quote! {
/// Bytecode of the #name contract
pub static #bytecode_name: #ethers_contract::Lazy<#ethers_core::types::Bytes> = #ethers_contract::Lazy::new(|| #hex_bytecode.parse()
Expand Down
12 changes: 6 additions & 6 deletions ethers-contract/ethers-contract-abigen/src/contract/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Context {
.map(|function| {
let signature = function.abi_signature();
self.expand_function(function, aliases.get(&signature).cloned())
.with_context(|| format!("error expanding function '{}'", signature))
.with_context(|| format!("error expanding function '{signature}'"))
})
.collect::<Result<Vec<_>>>()?;

Expand Down Expand Up @@ -593,7 +593,7 @@ impl Context {
name_conflicts(*idx, &diffs)
{
needs_alias_for_first_fun_using_idx = true;
format!("{}{}", overloaded_fun.name.to_snake_case(), idx)
format!("{}{idx}", overloaded_fun.name.to_snake_case())
} else {
format!(
"{}_with_{}",
Expand All @@ -608,7 +608,7 @@ impl Context {
name_conflicts(*idx, &diffs)
{
needs_alias_for_first_fun_using_idx = true;
format!("{}{}", overloaded_fun.name.to_snake_case(), idx)
format!("{}{idx}", overloaded_fun.name.to_snake_case())
} else {
// 1 + n additional input params
let and = diff
Expand All @@ -632,7 +632,7 @@ impl Context {

if needs_alias_for_first_fun_using_idx {
// insert an alias for the root duplicated call
let prev_alias = format!("{}{}", first_fun.name.to_snake_case(), first_fun_idx);
let prev_alias = format!("{}{first_fun_idx}", first_fun.name.to_snake_case());

let alias = MethodAlias::new(&prev_alias);

Expand Down Expand Up @@ -698,9 +698,9 @@ fn expand_struct_name_postfix(
postfix: &str,
) -> Ident {
let name = if let Some(alias) = alias {
format!("{}{}", alias.struct_name, postfix)
format!("{}{postfix}", alias.struct_name)
} else {
format!("{}{}", util::safe_pascal_case(&function.name), postfix)
format!("{}{postfix}", util::safe_pascal_case(&function.name))
};
util::ident(&name)
}
Expand Down
10 changes: 5 additions & 5 deletions ethers-contract/ethers-contract-abigen/src/contract/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ impl Context {
"".to_string()
};

let abi_signature = format!("{}({})", name, sig,);
let abi_signature = format!("{name}({sig})",);

let abi_signature_doc = util::expand_doc(&format!("`{}`", abi_signature));
let abi_signature_doc = util::expand_doc(&format!("`{abi_signature}`"));

// use the same derives as for events
let derives = util::expand_derives(&self.event_derives);
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Context {
param_types.iter().map(|kind| kind.to_string()).collect::<Vec<_>>().join(","),
);

let abi_signature_doc = util::expand_doc(&format!("`{}`", abi_signature));
let abi_signature_doc = util::expand_doc(&format!("`{abi_signature}`"));

let name = util::ident(name);

Expand Down Expand Up @@ -392,12 +392,12 @@ fn insert_rust_type_name(
let mut other_name = name.clone();
// name collision `A.name` `B.name`, rename to `AName`, `BName`
if !other_projections.is_empty() {
other_name = format!("{}{}", other_projections.remove(0).to_pascal_case(), other_name);
other_name = format!("{}{other_name}", other_projections.remove(0).to_pascal_case());
}
insert_rust_type_name(type_names, other_name, other_projections, other_id);

if !projections.is_empty() {
name = format!("{}{}", projections.remove(0).to_pascal_case(), name);
name = format!("{}{name}", projections.remove(0).to_pascal_case());
}
insert_rust_type_name(type_names, name, projections, id);
} else {
Expand Down
4 changes: 2 additions & 2 deletions ethers-contract/ethers-contract-abigen/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ ethers = {{ git = "https://github.com/gakonst/ethers-rs", default-features = fal
mod_names.insert(shared.name.to_snake_case());
}

for module in mod_names.into_iter().map(|name| format!("pub mod {};", name)) {
writeln!(buf, "{}", module)?;
for module in mod_names.into_iter().map(|name| format!("pub mod {name};")) {
writeln!(buf, "{module}")?;
}

Ok(())
Expand Down
11 changes: 5 additions & 6 deletions ethers-contract/ethers-contract-abigen/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn get_local_contract(path: impl AsRef<str>) -> Result<String> {
#[cfg(not(target_arch = "wasm32"))]
fn get_http_contract(url: &Url) -> Result<String> {
let json = util::http_get(url.as_str())
.with_context(|| format!("failed to retrieve JSON from {}", url))?;
.with_context(|| format!("failed to retrieve JSON from {url}"))?;
Ok(json)
}

Expand All @@ -266,15 +266,14 @@ fn get_etherscan_contract(address: Address, domain: &str) -> Result<String> {
"snowtrace.io" => env::var("SNOWTRACE_API_KEY").ok(),
_ => None,
};
key_res.map(|key| format!("&apikey={}", key)).unwrap_or_default()
key_res.map(|key| format!("&apikey={key}")).unwrap_or_default()
};

let abi_url = format!(
"http://api.{}/api?module=contract&action=getabi&address={:?}&format=raw{}",
domain, address, api_key,
);
let abi =
util::http_get(&abi_url).context(format!("failed to retrieve ABI from {}", domain))?;
let abi = util::http_get(&abi_url).context(format!("failed to retrieve ABI from {domain}"))?;

if abi.starts_with("Contract source code not verified") {
eyre::bail!("Contract source code not verified: {:?}", address);
Expand All @@ -292,9 +291,9 @@ fn get_etherscan_contract(address: Address, domain: &str) -> Result<String> {
/// Retrieves a Truffle artifact or ABI from an npm package through `unpkg.io`.
#[cfg(not(target_arch = "wasm32"))]
fn get_npm_contract(package: &str) -> Result<String> {
let unpkg_url = format!("https://unpkg.io/{}", package);
let unpkg_url = format!("https://unpkg.io/{package}");
let json = util::http_get(&unpkg_url)
.with_context(|| format!("failed to retrieve JSON from for npm package {}", package))?;
.with_context(|| format!("failed to retrieve JSON from for npm package {package}"))?;

Ok(json)
}
Expand Down
6 changes: 3 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn ident(name: &str) -> Ident {
///
/// Parsing keywords like `self` can fail, in this case we add an underscore.
pub fn safe_ident(name: &str) -> Ident {
syn::parse_str::<SynIdent>(name).unwrap_or_else(|_| ident(&format!("{}_", name)))
syn::parse_str::<SynIdent>(name).unwrap_or_else(|_| ident(&format!("{name}_")))
}

/// Converts a `&str` to `snake_case` `String` while respecting identifier rules
Expand All @@ -35,7 +35,7 @@ pub fn safe_pascal_case(ident: &str) -> String {
/// respects identifier rules, such as, an identifier must not start with a numeric char
fn safe_identifier_name(name: String) -> String {
if name.starts_with(|c: char| c.is_numeric()) {
format!("_{}", name)
format!("_{name}")
} else {
name
}
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn preserve_underscore_delim(ident: &str, alias: &str) -> String {
/// identifiers that are reserved keywords get `_` appended to them.
pub fn expand_input_name(index: usize, name: &str) -> TokenStream {
let name_str = match name {
"" => format!("p{}", index),
"" => format!("p{index}"),
n => n.to_snake_case(),
};
let name = safe_ident(&name_str);
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/ethers-contract-derive/src/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Parse for Parameter {
_ => {
return Err(ParseError::new(
name.span(),
format!("unexpected named parameter `{}`", name),
format!("unexpected named parameter `{name}`"),
))
}
};
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/ethers-contract-derive/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) fn derive_eth_call_impl(input: DeriveInput) -> TokenStream {
) {
Ok(derived) => derived,
Err(err) => {
Error::new(span, format!("Unable to determine ABI for `{}` : {}", src, err))
Error::new(span, format!("Unable to determine ABI for `{src}` : {err}"))
.to_compile_error()
}
}
Expand Down
6 changes: 3 additions & 3 deletions ethers-contract/ethers-contract-derive/src/calllike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ pub fn parse_calllike_attributes(
Meta::Path(path) => {
return Err(Error::new(
path.span(),
format!("unrecognized {} parameter", attr_name),
format!("unrecognized {attr_name} parameter"),
)
.to_compile_error())
}
Meta::List(meta) => {
return Err(Error::new(
meta.path.span(),
format!("unrecognized {} parameter", attr_name),
format!("unrecognized {attr_name} parameter"),
)
.to_compile_error())
}
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn parse_calllike_attributes(
} else {
return Err(Error::new(
meta.span(),
format!("unrecognized {} parameter", attr_name),
format!("unrecognized {attr_name} parameter"),
)
.to_compile_error())
}
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/ethers-contract-derive/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn derive_eth_error_impl(input: DeriveInput) -> TokenStream {
) {
Ok(derived) => derived,
Err(err) => {
Error::new(span, format!("Unable to determine ABI for `{}` : {}", src, err))
Error::new(span, format!("Unable to determine ABI for `{src}` : {err}"))
.to_compile_error()
}
}
Expand Down
12 changes: 6 additions & 6 deletions ethers-contract/ethers-contract-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,20 @@ pub fn derive_abi_inputs_from_fields(
Fields::Unit => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for empty structs and unit", trait_name),
format!("{trait_name} cannot be derived for empty structs and unit"),
))
}
},
Data::Enum(_) => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for enums", trait_name),
format!("{trait_name} cannot be derived for enums"),
))
}
Data::Union(_) => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for unions", trait_name),
format!("{trait_name} cannot be derived for unions"),
))
}
};
Expand Down Expand Up @@ -258,20 +258,20 @@ pub fn derive_abi_parameters_array(
Fields::Unit => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for empty structs and unit", trait_name),
format!("{trait_name} cannot be derived for empty structs and unit"),
))
}
},
Data::Enum(_) => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for enums", trait_name),
format!("{trait_name} cannot be derived for enums"),
))
}
Data::Union(_) => {
return Err(Error::new(
input.span(),
format!("{} cannot be derived for unions", trait_name),
format!("{trait_name} cannot be derived for unions"),
))
}
};
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/src/multicall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TryFrom<u8> for MulticallVersion {
1 => Ok(MulticallVersion::Multicall),
2 => Ok(MulticallVersion::Multicall2),
3 => Ok(MulticallVersion::Multicall3),
_ => Err(format!("Invalid Multicall version: {}. Accepted values: 1, 2, 3.", v)),
_ => Err(format!("Invalid Multicall version: {v}. Accepted values: 1, 2, 3.")),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ethers-contract/tests/it/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn can_gen_structs_readable() {
assert_codec::<Value>();
assert_codec::<Addresses>();
let encoded = addr.clone().encode();
let other = Addresses::decode(&encoded).unwrap();
let other = Addresses::decode(encoded).unwrap();
assert_eq!(addr, other);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ fn can_gen_return_struct() {
binding: T,
) {
let encoded = binding.clone().encode();
let decoded = T::decode(&encoded).unwrap();
let decoded = T::decode(encoded).unwrap();
assert_eq!(binding, decoded);
}

Expand Down
10 changes: 5 additions & 5 deletions ethers-contract/tests/it/common/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ fn eth_display_works() {
hex::encode(&item.v),
);

assert_eq!(val, format!("{}", item));
assert_eq!(val, format!("{item}"));
}

#[test]
Expand All @@ -408,9 +408,9 @@ fn eth_display_works_for_human_readable() {
);

let log = LogFilter("abc".to_string());
assert_eq!("abc".to_string(), format!("{}", log));
assert_eq!("abc".to_string(), format!("{log}"));
let log = Log2Filter { x: "abc".to_string() };
assert_eq!("abc".to_string(), format!("{}", log));
assert_eq!("abc".to_string(), format!("{log}"));
}

#[test]
Expand Down Expand Up @@ -493,7 +493,7 @@ fn can_derive_abi_codec() {
let val = SomeType { inner: Default::default(), msg: "hello".to_string() };

let encoded = val.clone().encode();
let other = SomeType::decode(&encoded).unwrap();
let other = SomeType::decode(encoded).unwrap();
assert_eq!(val, other);
}

Expand Down Expand Up @@ -603,7 +603,7 @@ fn eth_display_works_on_ethers_bytes() {
}
let call = LogBytesCall { p_0: hex::decode(b"aaaaaa").unwrap().into() };

let s = format!("{}", call);
let s = format!("{call}");
assert_eq!(s, "0xaaaaaa");
}

Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct ValueChanged {
/// compiles the given contract and returns the ABI and Bytecode
#[track_caller]
pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) {
let path = format!("./tests/solidity-contracts/{}", filename);
let path = format!("./tests/solidity-contracts/{filename}");
let compiled = Solc::default().compile_source(&path).unwrap();
let contract = compiled.get(&path, name).expect("could not find contract");
let (abi, bin, _) = contract.into_parts_or_default();
Expand Down
12 changes: 6 additions & 6 deletions ethers-core/src/abi/human_readable/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ impl<'input> Token<'input> {
impl<'input> fmt::Display for Token<'input> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Token::Identifier(id) => write!(f, "{}", id),
Token::Number(num) => write!(f, "{}", num),
Token::HexNumber(num) => write!(f, "0x{}", num),
Token::Uint(w) => write!(f, "uint{}", w),
Token::Int(w) => write!(f, "int{}", w),
Token::Bytes(w) => write!(f, "bytes{}", w),
Token::Identifier(id) => write!(f, "{id}"),
Token::Number(num) => write!(f, "{num}"),
Token::HexNumber(num) => write!(f, "0x{num}"),
Token::Uint(w) => write!(f, "uint{w}"),
Token::Int(w) => write!(f, "int{w}"),
Token::Bytes(w) => write!(f, "bytes{w}"),
Token::Byte => write!(f, "byte"),
Token::DynamicBytes => write!(f, "bytes"),
Token::Semicolon => write!(f, ";"),
Expand Down
2 changes: 1 addition & 1 deletion ethers-core/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ErrorExt for ethabi::AbiError {
return format!("{}()", self.name)
}
let inputs = self.inputs.iter().map(|p| p.kind.to_string()).collect::<Vec<_>>().join(",");
format!("{}({})", self.name, inputs)
format!("{}({inputs})", self.name)
}

fn selector(&self) -> Selector {
Expand Down
Loading