Skip to content

Commit ea6a08f

Browse files
DaniPopeshexiaoyuan
authored andcommitted
chore: clippy (gakonst#1812)
* chore: clippy * fmt
1 parent ad0c144 commit ea6a08f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+247
-248
lines changed

Diff for: ethers-contract/ethers-contract-abigen/src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ where
337337
if not_aliased.len() > 1 {
338338
let mut overloaded_aliases = Vec::new();
339339
for (idx, (sig, name)) in not_aliased.into_iter().enumerate() {
340-
let unique_name = format!("{}{}", name, idx + 1);
340+
let unique_name = format!("{name}{}", idx + 1);
341341
overloaded_aliases.push((sig, get_ident(&unique_name)));
342342
}
343343
aliases.extend(overloaded_aliases);

Diff for: ethers-contract/ethers-contract-abigen/src/contract/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
}
6565

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

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

117117
let bytecode = if let Some(ref bytecode) = cx.contract_bytecode {
118118
let bytecode_name = cx.inline_bytecode_ident();
119-
let hex_bytecode = format!("{}", bytecode);
119+
let hex_bytecode = format!("{bytecode}");
120120
quote! {
121121
/// Bytecode of the #name contract
122122
pub static #bytecode_name: #ethers_contract::Lazy<#ethers_core::types::Bytes> = #ethers_contract::Lazy::new(|| #hex_bytecode.parse()

Diff for: ethers-contract/ethers-contract-abigen/src/contract/methods.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Context {
3434
.map(|function| {
3535
let signature = function.abi_signature();
3636
self.expand_function(function, aliases.get(&signature).cloned())
37-
.with_context(|| format!("error expanding function '{}'", signature))
37+
.with_context(|| format!("error expanding function '{signature}'"))
3838
})
3939
.collect::<Result<Vec<_>>>()?;
4040

@@ -593,7 +593,7 @@ impl Context {
593593
name_conflicts(*idx, &diffs)
594594
{
595595
needs_alias_for_first_fun_using_idx = true;
596-
format!("{}{}", overloaded_fun.name.to_snake_case(), idx)
596+
format!("{}{idx}", overloaded_fun.name.to_snake_case())
597597
} else {
598598
format!(
599599
"{}_with_{}",
@@ -608,7 +608,7 @@ impl Context {
608608
name_conflicts(*idx, &diffs)
609609
{
610610
needs_alias_for_first_fun_using_idx = true;
611-
format!("{}{}", overloaded_fun.name.to_snake_case(), idx)
611+
format!("{}{idx}", overloaded_fun.name.to_snake_case())
612612
} else {
613613
// 1 + n additional input params
614614
let and = diff
@@ -632,7 +632,7 @@ impl Context {
632632

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

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

@@ -698,9 +698,9 @@ fn expand_struct_name_postfix(
698698
postfix: &str,
699699
) -> Ident {
700700
let name = if let Some(alias) = alias {
701-
format!("{}{}", alias.struct_name, postfix)
701+
format!("{}{postfix}", alias.struct_name)
702702
} else {
703-
format!("{}{}", util::safe_pascal_case(&function.name), postfix)
703+
format!("{}{postfix}", util::safe_pascal_case(&function.name))
704704
};
705705
util::ident(&name)
706706
}

Diff for: ethers-contract/ethers-contract-abigen/src/contract/structs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ impl Context {
129129
"".to_string()
130130
};
131131

132-
let abi_signature = format!("{}({})", name, sig,);
132+
let abi_signature = format!("{name}({sig})",);
133133

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

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

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

189189
let name = util::ident(name);
190190

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

399399
if !projections.is_empty() {
400-
name = format!("{}{}", projections.remove(0).to_pascal_case(), name);
400+
name = format!("{}{name}", projections.remove(0).to_pascal_case());
401401
}
402402
insert_rust_type_name(type_names, name, projections, id);
403403
} else {

Diff for: ethers-contract/ethers-contract-abigen/src/multi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ ethers = {{ git = "https://github.com/gakonst/ethers-rs", default-features = fal
598598
mod_names.insert(shared.name.to_snake_case());
599599
}
600600

601-
for module in mod_names.into_iter().map(|name| format!("pub mod {};", name)) {
602-
writeln!(buf, "{}", module)?;
601+
for module in mod_names.into_iter().map(|name| format!("pub mod {name};")) {
602+
writeln!(buf, "{module}")?;
603603
}
604604

605605
Ok(())

Diff for: ethers-contract/ethers-contract-abigen/src/source.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn get_local_contract(path: impl AsRef<str>) -> Result<String> {
248248
#[cfg(not(target_arch = "wasm32"))]
249249
fn get_http_contract(url: &Url) -> Result<String> {
250250
let json = util::http_get(url.as_str())
251-
.with_context(|| format!("failed to retrieve JSON from {}", url))?;
251+
.with_context(|| format!("failed to retrieve JSON from {url}"))?;
252252
Ok(json)
253253
}
254254

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

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

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

299298
Ok(json)
300299
}

Diff for: ethers-contract/ethers-contract-abigen/src/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn ident(name: &str) -> Ident {
1919
///
2020
/// Parsing keywords like `self` can fail, in this case we add an underscore.
2121
pub fn safe_ident(name: &str) -> Ident {
22-
syn::parse_str::<SynIdent>(name).unwrap_or_else(|_| ident(&format!("{}_", name)))
22+
syn::parse_str::<SynIdent>(name).unwrap_or_else(|_| ident(&format!("{name}_")))
2323
}
2424

2525
/// Converts a `&str` to `snake_case` `String` while respecting identifier rules
@@ -35,7 +35,7 @@ pub fn safe_pascal_case(ident: &str) -> String {
3535
/// respects identifier rules, such as, an identifier must not start with a numeric char
3636
fn safe_identifier_name(name: String) -> String {
3737
if name.starts_with(|c: char| c.is_numeric()) {
38-
format!("_{}", name)
38+
format!("_{name}")
3939
} else {
4040
name
4141
}
@@ -76,7 +76,7 @@ pub fn preserve_underscore_delim(ident: &str, alias: &str) -> String {
7676
/// identifiers that are reserved keywords get `_` appended to them.
7777
pub fn expand_input_name(index: usize, name: &str) -> TokenStream {
7878
let name_str = match name {
79-
"" => format!("p{}", index),
79+
"" => format!("p{index}"),
8080
n => n.to_snake_case(),
8181
};
8282
let name = safe_ident(&name_str);

Diff for: ethers-contract/ethers-contract-derive/src/abigen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Parse for Parameter {
184184
_ => {
185185
return Err(ParseError::new(
186186
name.span(),
187-
format!("unexpected named parameter `{}`", name),
187+
format!("unexpected named parameter `{name}`"),
188188
))
189189
}
190190
};

Diff for: ethers-contract/ethers-contract-derive/src/call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) fn derive_eth_call_impl(input: DeriveInput) -> TokenStream {
3333
) {
3434
Ok(derived) => derived,
3535
Err(err) => {
36-
Error::new(span, format!("Unable to determine ABI for `{}` : {}", src, err))
36+
Error::new(span, format!("Unable to determine ABI for `{src}` : {err}"))
3737
.to_compile_error()
3838
}
3939
}

Diff for: ethers-contract/ethers-contract-derive/src/calllike.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ pub fn parse_calllike_attributes(
3232
Meta::Path(path) => {
3333
return Err(Error::new(
3434
path.span(),
35-
format!("unrecognized {} parameter", attr_name),
35+
format!("unrecognized {attr_name} parameter"),
3636
)
3737
.to_compile_error())
3838
}
3939
Meta::List(meta) => {
4040
return Err(Error::new(
4141
meta.path.span(),
42-
format!("unrecognized {} parameter", attr_name),
42+
format!("unrecognized {attr_name} parameter"),
4343
)
4444
.to_compile_error())
4545
}
@@ -85,7 +85,7 @@ pub fn parse_calllike_attributes(
8585
} else {
8686
return Err(Error::new(
8787
meta.span(),
88-
format!("unrecognized {} parameter", attr_name),
88+
format!("unrecognized {attr_name} parameter"),
8989
)
9090
.to_compile_error())
9191
}

Diff for: ethers-contract/ethers-contract-derive/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) fn derive_eth_error_impl(input: DeriveInput) -> TokenStream {
3232
) {
3333
Ok(derived) => derived,
3434
Err(err) => {
35-
Error::new(span, format!("Unable to determine ABI for `{}` : {}", src, err))
35+
Error::new(span, format!("Unable to determine ABI for `{src}` : {err}"))
3636
.to_compile_error()
3737
}
3838
}

Diff for: ethers-contract/ethers-contract-derive/src/utils.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,20 @@ pub fn derive_abi_inputs_from_fields(
168168
Fields::Unit => {
169169
return Err(Error::new(
170170
input.span(),
171-
format!("{} cannot be derived for empty structs and unit", trait_name),
171+
format!("{trait_name} cannot be derived for empty structs and unit"),
172172
))
173173
}
174174
},
175175
Data::Enum(_) => {
176176
return Err(Error::new(
177177
input.span(),
178-
format!("{} cannot be derived for enums", trait_name),
178+
format!("{trait_name} cannot be derived for enums"),
179179
))
180180
}
181181
Data::Union(_) => {
182182
return Err(Error::new(
183183
input.span(),
184-
format!("{} cannot be derived for unions", trait_name),
184+
format!("{trait_name} cannot be derived for unions"),
185185
))
186186
}
187187
};
@@ -258,20 +258,20 @@ pub fn derive_abi_parameters_array(
258258
Fields::Unit => {
259259
return Err(Error::new(
260260
input.span(),
261-
format!("{} cannot be derived for empty structs and unit", trait_name),
261+
format!("{trait_name} cannot be derived for empty structs and unit"),
262262
))
263263
}
264264
},
265265
Data::Enum(_) => {
266266
return Err(Error::new(
267267
input.span(),
268-
format!("{} cannot be derived for enums", trait_name),
268+
format!("{trait_name} cannot be derived for enums"),
269269
))
270270
}
271271
Data::Union(_) => {
272272
return Err(Error::new(
273273
input.span(),
274-
format!("{} cannot be derived for unions", trait_name),
274+
format!("{trait_name} cannot be derived for unions"),
275275
))
276276
}
277277
};

Diff for: ethers-contract/src/multicall/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl TryFrom<u8> for MulticallVersion {
140140
1 => Ok(MulticallVersion::Multicall),
141141
2 => Ok(MulticallVersion::Multicall2),
142142
3 => Ok(MulticallVersion::Multicall3),
143-
_ => Err(format!("Invalid Multicall version: {}. Accepted values: 1, 2, 3.", v)),
143+
_ => Err(format!("Invalid Multicall version: {v}. Accepted values: 1, 2, 3.")),
144144
}
145145
}
146146
}

Diff for: ethers-contract/tests/it/abigen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn can_gen_structs_readable() {
8585
assert_codec::<Value>();
8686
assert_codec::<Addresses>();
8787
let encoded = addr.clone().encode();
88-
let other = Addresses::decode(&encoded).unwrap();
88+
let other = Addresses::decode(encoded).unwrap();
8989
assert_eq!(addr, other);
9090
}
9191

@@ -178,7 +178,7 @@ fn can_gen_return_struct() {
178178
binding: T,
179179
) {
180180
let encoded = binding.clone().encode();
181-
let decoded = T::decode(&encoded).unwrap();
181+
let decoded = T::decode(encoded).unwrap();
182182
assert_eq!(binding, decoded);
183183
}
184184

Diff for: ethers-contract/tests/it/common/derive.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn eth_display_works() {
394394
hex::encode(&item.v),
395395
);
396396

397-
assert_eq!(val, format!("{}", item));
397+
assert_eq!(val, format!("{item}"));
398398
}
399399

400400
#[test]
@@ -408,9 +408,9 @@ fn eth_display_works_for_human_readable() {
408408
);
409409

410410
let log = LogFilter("abc".to_string());
411-
assert_eq!("abc".to_string(), format!("{}", log));
411+
assert_eq!("abc".to_string(), format!("{log}"));
412412
let log = Log2Filter { x: "abc".to_string() };
413-
assert_eq!("abc".to_string(), format!("{}", log));
413+
assert_eq!("abc".to_string(), format!("{log}"));
414414
}
415415

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

495495
let encoded = val.clone().encode();
496-
let other = SomeType::decode(&encoded).unwrap();
496+
let other = SomeType::decode(encoded).unwrap();
497497
assert_eq!(val, other);
498498
}
499499

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

606-
let s = format!("{}", call);
606+
let s = format!("{call}");
607607
assert_eq!(s, "0xaaaaaa");
608608
}
609609

Diff for: ethers-contract/tests/it/common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct ValueChanged {
3131
/// compiles the given contract and returns the ABI and Bytecode
3232
#[track_caller]
3333
pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) {
34-
let path = format!("./tests/solidity-contracts/{}", filename);
34+
let path = format!("./tests/solidity-contracts/{filename}");
3535
let compiled = Solc::default().compile_source(&path).unwrap();
3636
let contract = compiled.get(&path, name).expect("could not find contract");
3737
let (abi, bin, _) = contract.into_parts_or_default();

Diff for: ethers-core/src/abi/human_readable/lexer.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ impl<'input> Token<'input> {
9494
impl<'input> fmt::Display for Token<'input> {
9595
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9696
match self {
97-
Token::Identifier(id) => write!(f, "{}", id),
98-
Token::Number(num) => write!(f, "{}", num),
99-
Token::HexNumber(num) => write!(f, "0x{}", num),
100-
Token::Uint(w) => write!(f, "uint{}", w),
101-
Token::Int(w) => write!(f, "int{}", w),
102-
Token::Bytes(w) => write!(f, "bytes{}", w),
97+
Token::Identifier(id) => write!(f, "{id}"),
98+
Token::Number(num) => write!(f, "{num}"),
99+
Token::HexNumber(num) => write!(f, "0x{num}"),
100+
Token::Uint(w) => write!(f, "uint{w}"),
101+
Token::Int(w) => write!(f, "int{w}"),
102+
Token::Bytes(w) => write!(f, "bytes{w}"),
103103
Token::Byte => write!(f, "byte"),
104104
Token::DynamicBytes => write!(f, "bytes"),
105105
Token::Semicolon => write!(f, ";"),

Diff for: ethers-core/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl ErrorExt for ethabi::AbiError {
9595
return format!("{}()", self.name)
9696
}
9797
let inputs = self.inputs.iter().map(|p| p.kind.to_string()).collect::<Vec<_>>().join(",");
98-
format!("{}({})", self.name, inputs)
98+
format!("{}({inputs})", self.name)
9999
}
100100

101101
fn selector(&self) -> Selector {

0 commit comments

Comments
 (0)