Skip to content

Commit 9e98c0e

Browse files
authored
Apply Clippy's uninlined_format_args lint (#7361)
## Description This PR improves the readability of `format!`, `write!`, etc. macros by rolling out the Clippy fixes for the `uninlined_format_args` lint. `cargo clippy` started showing this lint after locally switching to Cargo v1.88.0. Additionally, the PR: - replaces a few occurrences of `io::Error::new(std::io::ErrorKind::Other, <msg>)` with `io::Error::other(<msg>)`. - replaces a single occurrence of `if params.iter().any(|&p| p == "all")` with `if params.contains(&"all")`. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 8cb7c57 commit 9e98c0e

File tree

108 files changed

+366
-499
lines changed

Some content is hidden

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

108 files changed

+366
-499
lines changed

forc-pkg/src/manifest/dep_modifier.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl fmt::Display for Section {
287287
Section::Deps => "dependencies",
288288
Section::ContractDeps => "contract-dependencies",
289289
};
290-
write!(f, "{}", section)
290+
write!(f, "{section}")
291291
}
292292
}
293293

@@ -335,12 +335,12 @@ impl Section {
335335
Dependency::Simple(ver) => {
336336
let mut inline = InlineTable::default();
337337
inline.insert("version", Value::from(ver.to_string()));
338-
inline.insert("salt", Value::from(format!("0x{}", salt)));
338+
inline.insert("salt", Value::from(format!("0x{salt}")));
339339
Item::Value(toml_edit::Value::InlineTable(inline))
340340
}
341341
Dependency::Detailed(details) => {
342342
let mut inline = generate_table(details);
343-
inline.insert("salt", Value::from(format!("0x{}", salt)));
343+
inline.insert("salt", Value::from(format!("0x{salt}")));
344344
Item::Value(toml_edit::Value::InlineTable(inline))
345345
}
346346
};
@@ -445,11 +445,10 @@ mod tests {
445445
authors = ["Test"]
446446
entry = "main.sw"
447447
license = "MIT"
448-
name = "{}"
448+
name = "{name}"
449449
450450
[dependencies]
451-
"#,
452-
name
451+
"#
453452
);
454453
fs::write(base_path.join("Forc.toml"), forc_toml)?;
455454

@@ -500,11 +499,10 @@ mod tests {
500499
authors = ["Test"]
501500
entry = "main.sw"
502501
license = "MIT"
503-
name = "{}"
502+
name = "{name}"
504503
505504
[dependencies]
506-
"#,
507-
name
505+
"#
508506
);
509507
fs::write(member_path.join("Forc.toml"), forc_toml)?;
510508

@@ -942,7 +940,7 @@ mod tests {
942940
let base_path = temp_dir.path();
943941
let package_dir = base_path.join("pkg1");
944942
let dep = "pkg1";
945-
let resp = format!("cannot add `{}` as a dependency to itself", dep);
943+
let resp = format!("cannot add `{dep}` as a dependency to itself");
946944

947945
let manifest_file = ManifestFile::from_dir(base_path).unwrap();
948946
let members = manifest_file.member_manifests().unwrap();
@@ -1062,7 +1060,7 @@ mod tests {
10621060
);
10631061
assert_eq!(
10641062
contract_table.get("salt").unwrap().as_str(),
1065-
Some(format!("0x{}", hex_salt).as_str())
1063+
Some(format!("0x{hex_salt}").as_str())
10661064
);
10671065
}
10681066

forc-pkg/src/manifest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl FromStr for HexSalt {
277277
impl Display for HexSalt {
278278
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
279279
let salt = self.0;
280-
write!(f, "{}", salt)
280+
write!(f, "{salt}")
281281
}
282282
}
283283

forc-pkg/src/pkg.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,7 @@ impl BuildPlan {
700700
// longer exists at its specified location, etc. We must first remove all invalid nodes
701701
// before we can determine what we need to fetch.
702702
let invalid_deps = validate_graph(&graph, manifests)?;
703-
let members: HashSet<String> = manifests
704-
.iter()
705-
.map(|(member_name, _)| member_name.clone())
706-
.collect();
703+
let members: HashSet<String> = manifests.keys().cloned().collect();
707704
remove_deps(&mut graph, &members, &invalid_deps);
708705

709706
// We know that the remaining nodes have valid paths, otherwise they would have been
@@ -741,11 +738,11 @@ impl BuildPlan {
741738
}
742739
println_action_green(
743740
"Creating",
744-
&format!("a new `Forc.lock` file. (Cause: {})", cause),
741+
&format!("a new `Forc.lock` file. (Cause: {cause})"),
745742
);
746743
let member_names = manifests
747-
.iter()
748-
.map(|(_, manifest)| manifest.project.name.to_string())
744+
.values()
745+
.map(|manifest| manifest.project.name.to_string())
749746
.collect();
750747
crate::lock::print_diff(&member_names, &lock_diff);
751748
let string = toml::ser::to_string_pretty(&new_lock)

forc-pkg/src/source/ipfs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ impl source::Fetch for Pinned {
9393
println_action_green(
9494
"Fetching",
9595
&format!(
96-
"from {}. Note: This can take several minutes.",
97-
ipfs_node_gateway_url
96+
"from {ipfs_node_gateway_url}. Note: This can take several minutes."
9897
),
9998
);
10099
cid.fetch_with_gateway_url(&ipfs_node_gateway_url, &dest)
@@ -274,7 +273,7 @@ mod tests {
274273

275274
// Add files
276275
for (path, content) in files {
277-
let full_path = format!("test-project/{}", path);
276+
let full_path = format!("test-project/{path}");
278277
let header = create_header(&full_path, content.len() as u64);
279278
ar.append(&header, content.as_bytes()).unwrap();
280279
}

forc-pkg/src/source/reg/index_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ mod tests {
354354

355355
// Test round-trip serialization
356356
let serialized = serde_json::to_string_pretty(&deserialized).unwrap();
357-
println!("Re-serialized JSON: {}", serialized);
357+
println!("Re-serialized JSON: {serialized}");
358358

359359
// Deserialize again to ensure it's valid
360360
let re_deserialized: IndexFile = serde_json::from_str(&serialized).unwrap();

forc-pkg/src/source/reg/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,17 @@ async fn fetch(fetch_id: u64, pinned: &Pinned, ipfs_node: &IPFSNode) -> anyhow::
469469
IPFSNode::WithUrl(gateway_url) => {
470470
println_action_green(
471471
"Fetching",
472-
&format!("from {}. Note: This can take several minutes.", gateway_url),
472+
&format!("from {gateway_url}. Note: This can take several minutes."),
473473
);
474474
cid.fetch_with_gateway_url(gateway_url, &path).await
475475
}
476476
};
477477

478478
// If IPFS fails, try CDN fallback
479479
if let Err(ipfs_error) = ipfs_result {
480-
println_action_green("Warning", &format!("IPFS fetch failed: {}", ipfs_error));
480+
println_action_green("Warning", &format!("IPFS fetch failed: {ipfs_error}"));
481481
fetch_from_s3(pinned, &path).await.with_context(|| {
482-
format!(
483-
"Both IPFS and CDN fallback failed. IPFS error: {}",
484-
ipfs_error
485-
)
482+
format!("Both IPFS and CDN fallback failed. IPFS error: {ipfs_error}")
486483
})?;
487484
}
488485

@@ -600,10 +597,7 @@ where
600597

601598
let contents = index_response.text().await?;
602599
let index_file: IndexFile = serde_json::from_str(&contents).with_context(|| {
603-
format!(
604-
"Unable to deserialize a github registry lookup response. Body was: \"{}\"",
605-
contents
606-
)
600+
format!("Unable to deserialize a github registry lookup response. Body was: \"{contents}\"")
607601
})?;
608602

609603
let res = f(index_file).await?;

forc-plugins/forc-client/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ fn update_proxy_abi_decl_with_file(source_file_path: &Path, minified_json: &str)
3333

3434
// Prepare the replacement string for the `abigen!` macro
3535
let escaped_json = minified_json.replace('\\', "\\\\").replace('"', "\\\"");
36-
let new_abigen = format!(
37-
"abigen!(Contract(name = \"ProxyContract\", abi = \"{}\",));",
38-
escaped_json
39-
);
36+
let new_abigen =
37+
format!("abigen!(Contract(name = \"ProxyContract\", abi = \"{escaped_json}\",));");
4038

4139
// Use a regular expression to find and replace the `abigen!` macro
4240
let re = regex::Regex::new(r#"abigen!\(Contract\(name = "ProxyContract", abi = ".*?",\)\);"#)

forc-plugins/forc-client/src/bin/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn main() {
2121
}
2222
};
2323
if let Err(err) = forc_client::op::call(operation, command).await {
24-
println_error(&format!("{}", err));
24+
println_error(&format!("{err}"));
2525
std::process::exit(1);
2626
}
2727
}

forc-plugins/forc-client/src/bin/deploy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async fn main() {
66
init_tracing_subscriber(Default::default());
77
let command = forc_client::cmd::Deploy::parse();
88
if let Err(err) = forc_client::op::deploy(command).await {
9-
println_error(&format!("{}", err));
9+
println_error(&format!("{err}"));
1010
std::process::exit(1);
1111
}
1212
}

forc-plugins/forc-client/src/bin/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async fn main() {
66
init_tracing_subscriber(Default::default());
77
let command = forc_client::cmd::Run::parse();
88
if let Err(err) = forc_client::op::run(command).await {
9-
println_error(&format!("{}", err));
9+
println_error(&format!("{err}"));
1010
std::process::exit(1);
1111
}
1212
}

0 commit comments

Comments
 (0)