Skip to content

Commit c82ffb3

Browse files
committed
Addressed clippy warnings
1 parent a3fbd61 commit c82ffb3

File tree

31 files changed

+80
-90
lines changed

31 files changed

+80
-90
lines changed

cargo/bootstrap/bootstrap_installer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn install() -> std::io::Result<u64> {
2929

3030
fn main() {
3131
if let Err(err) = install() {
32-
eprintln!("{:?}", err);
32+
eprintln!("{err:?}");
3333
std::process::exit(1);
3434
};
3535
}

cargo/cargo_build_script_runner/bin.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn run_buildrs() -> Result<(), String> {
127127
format!(
128128
"Build script process failed{}\n--stdout:\n{}\n--stderr:\n{}",
129129
if let Some(exit_code) = process_output.status.code() {
130-
format!(" with exit code {}", exit_code)
130+
format!(" with exit code {exit_code}")
131131
} else {
132132
String::new()
133133
},
@@ -236,15 +236,14 @@ fn get_target_env_vars<P: AsRef<Path>>(rustc: &P) -> Result<BTreeMap<String, Str
236236
env::var("TARGET").expect("missing TARGET")
237237
))
238238
.output()
239-
.map_err(|err| format!("Error running rustc to get target information: {}", err))?;
239+
.map_err(|err| format!("Error running rustc to get target information: {err}"))?;
240240
if !output.status.success() {
241241
return Err(format!(
242-
"Error running rustc to get target information: {:?}",
243-
output
242+
"Error running rustc to get target information: {output:?}",
244243
));
245244
}
246245
let stdout = std::str::from_utf8(&output.stdout)
247-
.map_err(|err| format!("Non-UTF8 stdout from rustc: {:?}", err))?;
246+
.map_err(|err| format!("Non-UTF8 stdout from rustc: {err:?}"))?;
248247

249248
Ok(parse_rustc_cfg_output(stdout))
250249
}
@@ -280,7 +279,7 @@ fn main() {
280279
Ok(_) => 0,
281280
Err(err) => {
282281
// Neatly print errors
283-
eprintln!("{}", err);
282+
eprintln!("{err}");
284283
1
285284
}
286285
});

cargo/cargo_build_script_runner/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ impl BuildScriptOutput {
183183

184184
for flag in outputs {
185185
match flag {
186-
BuildScriptOutput::Cfg(e) => compile_flags.push(format!("--cfg={}", e)),
186+
BuildScriptOutput::Cfg(e) => compile_flags.push(format!("--cfg={e}")),
187187
BuildScriptOutput::Flags(e) => compile_flags.push(e.to_owned()),
188-
BuildScriptOutput::LinkArg(e) => compile_flags.push(format!("-Clink-arg={}", e)),
189-
BuildScriptOutput::LinkLib(e) => link_flags.push(format!("-l{}", e)),
190-
BuildScriptOutput::LinkSearch(e) => link_search_paths.push(format!("-L{}", e)),
188+
BuildScriptOutput::LinkArg(e) => compile_flags.push(format!("-Clink-arg={e}")),
189+
BuildScriptOutput::LinkLib(e) => link_flags.push(format!("-l{e}")),
190+
BuildScriptOutput::LinkSearch(e) => link_search_paths.push(format!("-L{e}")),
191191
_ => {}
192192
}
193193
}

crate_universe/src/cli/query.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,15 @@ pub fn query(opt: QueryOptions) -> Result<()> {
7070
&opt.rustc,
7171
)?;
7272
if digest != expected {
73-
return announce_repin(&format!(
74-
"Digests do not match: {:?} != {:?}",
75-
digest, expected
76-
));
73+
return announce_repin(&format!("Digests do not match: {digest:?} != {expected:?}",));
7774
}
7875

7976
// There is no need to repin
8077
Ok(())
8178
}
8279

8380
fn announce_repin(reason: &str) -> Result<()> {
84-
eprintln!("{}", reason);
81+
eprintln!("{reason}");
8582
println!("repin");
8683
Ok(())
8784
}

crate_universe/src/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl Add for CrateAnnotations {
286286
};
287287

288288
let concat_string = |lhs: &mut String, rhs: String| {
289-
*lhs = format!("{}{}", lhs, rhs);
289+
*lhs = format!("{lhs}{rhs}");
290290
};
291291

292292
#[rustfmt::skip]
@@ -405,8 +405,7 @@ impl<'de> Visitor<'de> for CrateIdVisitor {
405405
})
406406
.ok_or_else(|| {
407407
E::custom(format!(
408-
"Expected string value of `{{name}} {{version}}`. Got '{}'",
409-
v
408+
"Expected string value of `{{name}} {{version}}`. Got '{v}'"
410409
))
411410
})
412411
}

crate_universe/src/context/platforms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn resolve_cfg_platforms(
5656
// (`x86_64-unknown-linux-gun` vs `cfg(target = "x86_64-unkonwn-linux-gnu")`). So
5757
// in order to parse configurations, the text is renamed for the check but the
5858
// original is retained for comaptibility with the manifest.
59-
let rename = |cfg: &str| -> String { format!("cfg(target = \"{}\")", cfg) };
59+
let rename = |cfg: &str| -> String { format!("cfg(target = \"{cfg}\")") };
6060
let original_cfgs: HashMap<String, String> = configurations
6161
.iter()
6262
.filter(|cfg| !cfg.starts_with("cfg("))
@@ -73,8 +73,8 @@ pub fn resolve_cfg_platforms(
7373
})
7474
// Check the current configuration with against each supported triple
7575
.map(|cfg| {
76-
let expression = Expression::parse(&cfg)
77-
.context(format!("Failed to parse expression: '{}'", cfg))?;
76+
let expression =
77+
Expression::parse(&cfg).context(format!("Failed to parse expression: '{cfg}'"))?;
7878

7979
let triples = target_infos
8080
.iter()

crate_universe/src/lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn write_lockfile(lockfile: Context, path: &Path, dry_run: bool) -> Result<(
4040
let content = serde_json::to_string_pretty(&lockfile)?;
4141

4242
if dry_run {
43-
println!("{:#?}", content);
43+
println!("{content:#?}");
4444
} else {
4545
// Ensure the parent directory exists
4646
if let Some(parent) = path.parent() {

crate_universe/src/metadata/metadata_annotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ mod test {
549549
let result = Annotations::new(test::metadata::no_deps(), test::lockfile::no_deps(), config);
550550
assert!(result.is_err());
551551

552-
let result_str = format!("{:?}", result);
552+
let result_str = format!("{result:?}");
553553
assert!(result_str.contains("Unused annotations were provided. Please remove them"));
554554
assert!(result_str.contains("mock-crate"));
555555
}

crate_universe/src/rendering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn write_outputs(
134134
println!(
135135
"==============================================================================="
136136
);
137-
println!("{}\n", content);
137+
println!("{content}\n");
138138
}
139139
} else {
140140
for (path, content) in outputs {
@@ -513,7 +513,7 @@ mod test {
513513
assert!(build_file_content.replace(' ', "").contains(
514514
&rustc_flags
515515
.iter()
516-
.map(|s| format!("\"{}\",", s))
516+
.map(|s| format!("\"{s}\","))
517517
.collect::<Vec<String>>()
518518
.join("\n")
519519
));

crate_universe/src/rendering/template_engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl TemplateEngine {
214214
context.insert(
215215
"default_package_name",
216216
&match render_config.default_package_name.as_ref() {
217-
Some(pkg_name) => format!("\"{}\"", pkg_name),
217+
Some(pkg_name) => format!("\"{pkg_name}\""),
218218
None => "None".to_owned(),
219219
},
220220
);

crate_universe/src/splicing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ impl WorkspaceMetadata {
310310

311311
// Load the index for the current url
312312
let index = crates_index::Index::from_url(index_url)
313-
.with_context(|| format!("Failed to load index for url: {}", index_url))?;
313+
.with_context(|| format!("Failed to load index for url: {index_url}"))?;
314314

315315
// Ensure each index has a valid index config
316316
index.index_config().with_context(|| {
317-
format!("`config.json` not found in index: {}", index_url)
317+
format!("`config.json` not found in index: {index_url}")
318318
})?;
319319

320320
index

crate_universe/src/splicing/splicer.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a> SplicerKind<'a> {
118118
.keys()
119119
.map(|p| {
120120
p.normalize()
121-
.with_context(|| format!("Failed to normalize path {:?}", p))
121+
.with_context(|| format!("Failed to normalize path {p:?}"))
122122
})
123123
.collect::<Result<_, _>>()?,
124124
)
@@ -165,7 +165,7 @@ impl<'a> SplicerKind<'a> {
165165
.map(|member| {
166166
let path = root_manifest_dir.join(member).join("Cargo.toml");
167167
path.normalize()
168-
.with_context(|| format!("Failed to normalize path {:?}", path))
168+
.with_context(|| format!("Failed to normalize path {path:?}"))
169169
})
170170
.collect::<Result<BTreeSet<normpath::BasePathBuf>, _>>()?;
171171

@@ -178,10 +178,7 @@ impl<'a> SplicerKind<'a> {
178178
.map(|workspace_manifest_path| {
179179
let label = Label::from_absolute_path(workspace_manifest_path.as_path())
180180
.with_context(|| {
181-
format!(
182-
"Failed to identify label for path {:?}",
183-
workspace_manifest_path
184-
)
181+
format!("Failed to identify label for path {workspace_manifest_path:?}")
185182
})?;
186183
Ok(label.to_string())
187184
})
@@ -548,9 +545,8 @@ pub fn default_cargo_workspace_manifest(
548545
let mut manifest = cargo_toml::Manifest::from_str(&textwrap::dedent(&format!(
549546
r#"
550547
[workspace]
551-
resolver = "{}"
548+
resolver = "{resolver_version}"
552549
"#,
553-
resolver_version,
554550
)))
555551
.unwrap();
556552

@@ -867,7 +863,7 @@ mod test {
867863

868864
splicing_manifest.manifests.insert(
869865
manifest_path,
870-
Label::from_str(&format!("//{}:Cargo.toml", pkg)).unwrap(),
866+
Label::from_str(&format!("//{pkg}:Cargo.toml")).unwrap(),
871867
);
872868
}
873869

@@ -925,7 +921,7 @@ mod test {
925921

926922
splicing_manifest.manifests.insert(
927923
manifest_path,
928-
Label::from_str(&format!("//{}:Cargo.toml", pkg)).unwrap(),
924+
Label::from_str(&format!("//{pkg}:Cargo.toml")).unwrap(),
929925
);
930926
}
931927

@@ -1008,11 +1004,11 @@ mod test {
10081004

10091005
if is_root {
10101006
PackageId {
1011-
repr: format!("{} 0.0.1 (path+file://{})", name, workspace_root),
1007+
repr: format!("{name} 0.0.1 (path+file://{workspace_root})"),
10121008
}
10131009
} else {
10141010
PackageId {
1015-
repr: format!("{} 0.0.1 (path+file://{}/{})", name, workspace_root, name,),
1011+
repr: format!("{name} 0.0.1 (path+file://{workspace_root}/{name})"),
10161012
}
10171013
}
10181014
}

crate_universe/src/utils/starlark/label.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl FromStr for Label {
2323
let re = Regex::new(r"^(@@?[\w\d\-_\.]*)?/{0,2}([\w\d\-_\./+]+)?(:([\+\w\d\-_\./]+))?$")?;
2424
let cap = re
2525
.captures(s)
26-
.with_context(|| format!("Failed to parse label from string: {}", s))?;
26+
.with_context(|| format!("Failed to parse label from string: {s}"))?;
2727

2828
let repository = cap
2929
.get(1)
@@ -57,14 +57,14 @@ impl Display for Label {
5757
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5858
// Add the repository
5959
if let Some(repo) = &self.repository {
60-
write!(f, "@{}", repo)?;
60+
write!(f, "@{repo}")?;
6161
}
6262

6363
write!(f, "//")?;
6464

6565
// Add the package
6666
if let Some(pkg) = &self.package {
67-
write!(f, "{}", pkg)?;
67+
write!(f, "{pkg}")?;
6868
}
6969

7070
write!(f, ":{}", self.target)?;

crate_universe/src/utils/starlark/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<T: Ord> SelectList<T> {
5555
}
5656

5757
// TODO: This should probably be added to the [Select] trait
58-
pub fn get_iter<'a>(&'a self, config: Option<&String>) -> Option<btree_set::Iter<T>> {
58+
pub fn get_iter(&self, config: Option<&String>) -> Option<btree_set::Iter<T>> {
5959
match config {
6060
Some(conf) => self.selects.get(conf).map(|set| set.iter()),
6161
None => Some(self.common.iter()),

crate_universe/tools/cross_installer/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Options {
2323
fn prepare_workspace(workspace_root: &Path) {
2424
let src = PathBuf::from(env!("CROSS_CONFIG"));
2525
let dest = workspace_root.join("Cross.toml");
26-
println!("{:?} -> {:?}", src, dest);
26+
println!("{src:?} -> {dest:?}");
2727
fs::copy(src, dest).unwrap();
2828

2929
// Unfortunately, cross runs into issues when cross compiling incramentally.
@@ -46,7 +46,7 @@ fn execute_cross(working_dir: &Path, target_triple: &str) {
4646
.arg("--locked")
4747
.arg("--bin")
4848
.arg("cargo-bazel")
49-
.arg(format!("--target={}", target_triple))
49+
.arg(format!("--target={target_triple}"))
5050
.status()
5151
.unwrap();
5252

crate_universe/tools/urls_generator/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn locate_artifacts(artifacts_dir: &Path, url_prefix: &str) -> Vec<Artifact> {
7878
.map(|ext| format!(".{}", ext.to_string_lossy()))
7979
.unwrap_or_default();
8080
Artifact {
81-
url: format!("{}/{}-{}{}", url_prefix, stem, triple, extension),
81+
url: format!("{url_prefix}/{stem}-{triple}{extension}"),
8282
triple: triple.to_string(),
8383
sha256: calculate_sha256(&f_entry.path()),
8484
}

proto/optional_output_wrapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() {
5050
Err(e) => {
5151
println!("Usage: [optional_output1...optional_outputN] -- program [arg1...argn]");
5252
println!("{:?}", args());
53-
println!("{:?}", e);
53+
println!("{e:?}");
5454
-1
5555
}
5656
});

test/cargo_build_script/tools_exec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO: Remove this exception after https://github.com/rust-lang/rust-clippy/pull/10055 is released
2+
#![allow(clippy::uninlined_format_args)]
3+
14
#[test]
25
pub fn test_tool_exec() {
36
let tool_path = env!("TOOL_PATH");

test/chained_direct_deps/mod2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate mod1;
22

33
pub fn greeter(name: &str) -> String {
4-
format!("Hello, {}!", name)
4+
format!("Hello, {name}!")
55
}
66

77
pub fn default_greeter() -> String {

test/process_wrapper/rustc_quit_on_rmeta.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO: Remove this exception after https://github.com/rust-lang/rust-clippy/pull/10055 is released
2+
#![allow(clippy::uninlined_format_args)]
3+
14
#[cfg(test)]
25
mod test {
36
use std::path::PathBuf;
@@ -8,6 +11,7 @@ mod test {
811

912
/// fake_rustc runs the fake_rustc binary under process_wrapper with the specified
1013
/// process wrapper arguments. No arguments are passed to fake_rustc itself.
14+
///
1115
fn fake_rustc(process_wrapper_args: &[&'static str]) -> String {
1216
let r = Runfiles::create().unwrap();
1317
let fake_rustc = r.rlocation(

test/renamed_deps/mod2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate mod1;
22

33
pub fn greeter(name: &str) -> String {
4-
format!("Hello, {}!", name)
4+
format!("Hello, {name}!")
55
}
66

77
pub fn default_greeter() -> String {

test/unit/exports/lib_a/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub fn greeting_from(from: &str) -> String {
2-
format!("Hello from {}!", from)
2+
format!("Hello from {from}!")
33
}
44

55
pub fn greeting_a() -> String {

test/unit/is_proc_macro_dep/proc_macro_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro::TokenStream;
55
#[proc_macro]
66
pub fn make_answer(_item: TokenStream) -> TokenStream {
77
let answer = proc_macro_dep::proc_macro_dep();
8-
format!("fn answer() -> u32 {{ {} }}", answer)
8+
format!("fn answer() -> u32 {{ {answer} }}")
99
.parse()
1010
.unwrap()
1111
}

test/versioned_dylib/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020

2121
fn main() {
2222
let zero = unsafe { return_zero() };
23-
println!("Got {} from our shared lib", zero);
23+
println!("Got {zero} from our shared lib");
2424
}
2525

2626
#[cfg(test)]

0 commit comments

Comments
 (0)