Skip to content

Commit d3c85ef

Browse files
authored
Fix clippy warnings about not using variables in format! strings (#1489)
1 parent 7043e38 commit d3c85ef

File tree

6 files changed

+48
-53
lines changed

6 files changed

+48
-53
lines changed

src/bin/cc-shim.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() -> ExitCode {
2222

2323
// Find the first nonexistent candidate file to which the program's args can be written.
2424
let candidate = (0..).find_map(|i| {
25-
let candidate = out_dir.join(format!("out{}", i));
25+
let candidate = out_dir.join(format!("out{i}"));
2626

2727
if candidate.exists() {
2828
// If the file exists, commands have already run. Try again.
@@ -45,7 +45,7 @@ fn main() -> ExitCode {
4545

4646
(|| {
4747
for arg in args.clone() {
48-
writeln!(f, "{}", arg)?;
48+
writeln!(f, "{arg}")?;
4949
}
5050

5151
f.flush()?;

src/command_helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ impl CargoOutput {
5555

5656
pub(crate) fn print_metadata(&self, s: &dyn Display) {
5757
if self.metadata {
58-
println!("{}", s);
58+
println!("{s}");
5959
}
6060
}
6161

6262
pub(crate) fn print_warning(&self, arg: &dyn Display) {
6363
if self.warnings {
64-
println!("cargo:warning={}", arg);
64+
println!("cargo:warning={arg}");
6565
}
6666
}
6767

@@ -71,7 +71,7 @@ impl CargoOutput {
7171
println!("cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT");
7272
}
7373
if self.debug {
74-
println!("{}", arg);
74+
println!("{arg}");
7575
}
7676
}
7777

@@ -375,7 +375,7 @@ pub(crate) fn spawn(cmd: &mut Command, cargo_output: &CargoOutput) -> Result<Chi
375375
}
376376
}
377377

378-
cargo_output.print_debug(&format_args!("running: {:?}", cmd));
378+
cargo_output.print_debug(&format_args!("running: {cmd:?}"));
379379

380380
let cmd = ResetStderr(cmd);
381381
let child = cmd

src/flags.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ impl<'this> RustcCodegenFlags<'this> {
178178
tool.args.push(flag);
179179
} else {
180180
build.cargo_output.print_warning(&format!(
181-
"Inherited flag {:?} is not supported by the currently used CC",
182-
flag
181+
"Inherited flag {flag:?} is not supported by the currently used CC"
183182
));
184183
}
185184
};

src/lib.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Error {
382382

383383
impl From<io::Error> for Error {
384384
fn from(e: io::Error) -> Error {
385-
Error::new(ErrorKind::IOError, format!("{}", e))
385+
Error::new(ErrorKind::IOError, format!("{e}"))
386386
}
387387
}
388388

@@ -1463,7 +1463,7 @@ impl Build {
14631463

14641464
if self.link_lib_modifiers.is_empty() {
14651465
self.cargo_output
1466-
.print_metadata(&format_args!("cargo:rustc-link-lib=static={}", lib_name));
1466+
.print_metadata(&format_args!("cargo:rustc-link-lib=static={lib_name}"));
14671467
} else {
14681468
self.cargo_output.print_metadata(&format_args!(
14691469
"cargo:rustc-link-lib=static:{}={}",
@@ -1551,7 +1551,7 @@ impl Build {
15511551
bad => panic!("unsupported cudart option: {}", bad),
15521552
};
15531553
self.cargo_output
1554-
.print_metadata(&format_args!("cargo:rustc-link-lib={}", lib));
1554+
.print_metadata(&format_args!("cargo:rustc-link-lib={lib}"));
15551555
}
15561556
}
15571557

@@ -1965,7 +1965,7 @@ impl Build {
19651965
ToolFamily::Msvc { .. } => ':',
19661966
ToolFamily::Gnu | ToolFamily::Clang { .. } => '=',
19671967
};
1968-
cmd.push_cc_arg(format!("-std{}{}", separator, std).into());
1968+
cmd.push_cc_arg(format!("-std{separator}{std}").into());
19691969
}
19701970
for directory in self.include_directories.iter() {
19711971
cmd.args.push("-I".into());
@@ -2011,9 +2011,9 @@ impl Build {
20112011
}
20122012
for (key, value) in self.definitions.iter() {
20132013
if let Some(ref value) = *value {
2014-
cmd.args.push(format!("-D{}={}", key, value).into());
2014+
cmd.args.push(format!("-D{key}={value}").into());
20152015
} else {
2016-
cmd.args.push(format!("-D{}", key).into());
2016+
cmd.args.push(format!("-D{key}").into());
20172017
}
20182018
}
20192019

@@ -2069,7 +2069,7 @@ impl Build {
20692069
if opt_level == "z" && !cmd.is_like_clang() {
20702070
cmd.push_opt_unless_duplicate("-Os".into());
20712071
} else {
2072-
cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into());
2072+
cmd.push_opt_unless_duplicate(format!("-O{opt_level}").into());
20732073
}
20742074

20752075
if cmd.is_like_clang() && target.os == "android" {
@@ -2498,7 +2498,7 @@ impl Build {
24982498
match (self.cpp_set_stdlib.as_ref(), cmd.family) {
24992499
(None, _) => {}
25002500
(Some(stdlib), ToolFamily::Gnu) | (Some(stdlib), ToolFamily::Clang { .. }) => {
2501-
cmd.push_cc_arg(format!("-stdlib=lib{}", stdlib).into());
2501+
cmd.push_cc_arg(format!("-stdlib=lib{stdlib}").into());
25022502
}
25032503
_ => {
25042504
self.cargo_output.print_warning(&format_args!("cpp_set_stdlib is specified, but the {:?} compiler does not support this option, ignored", cmd.family));
@@ -2553,11 +2553,11 @@ impl Build {
25532553
cmd.arg("-PreDefine");
25542554
if let Some(ref value) = *value {
25552555
if let Ok(i) = value.parse::<i32>() {
2556-
cmd.arg(format!("{} SETA {}", key, i));
2556+
cmd.arg(format!("{key} SETA {i}"));
25572557
} else if value.starts_with('"') && value.ends_with('"') {
2558-
cmd.arg(format!("{} SETS {}", key, value));
2558+
cmd.arg(format!("{key} SETS {value}"));
25592559
} else {
2560-
cmd.arg(format!("{} SETS \"{}\"", key, value));
2560+
cmd.arg(format!("{key} SETS \"{value}\""));
25612561
}
25622562
} else {
25632563
cmd.arg(format!("{} SETL {}", key, "{TRUE}"));
@@ -2570,9 +2570,9 @@ impl Build {
25702570

25712571
for (key, value) in self.definitions.iter() {
25722572
if let Some(ref value) = *value {
2573-
cmd.arg(format!("-D{}={}", key, value));
2573+
cmd.arg(format!("-D{key}={value}"));
25742574
} else {
2575-
cmd.arg(format!("-D{}", key));
2575+
cmd.arg(format!("-D{key}"));
25762576
}
25772577
}
25782578
}
@@ -2619,7 +2619,7 @@ impl Build {
26192619
// MSVC linker will also be passed foo.lib, so be sure that both
26202620
// exist for now.
26212621

2622-
let lib_dst = dst.with_file_name(format!("{}.lib", lib_name));
2622+
let lib_dst = dst.with_file_name(format!("{lib_name}.lib"));
26232623
let _ = fs::remove_file(&lib_dst);
26242624
match fs::hard_link(dst, &lib_dst).or_else(|_| {
26252625
// if hard-link fails, just copy (ignoring the number of bytes written)
@@ -2852,7 +2852,7 @@ impl Build {
28522852
ToolFamily::Clang { zig_cc: false },
28532853
);
28542854
t.args.push("/c".into());
2855-
t.args.push(format!("{}.bat", tool).into());
2855+
t.args.push(format!("{tool}.bat").into());
28562856
Some(t)
28572857
} else {
28582858
Some(Tool::new(
@@ -2876,7 +2876,7 @@ impl Build {
28762876
msvc.to_string()
28772877
} else {
28782878
let cc = if target.abi == "llvm" { clang } else { gnu };
2879-
format!("{}.exe", cc)
2879+
format!("{cc}.exe")
28802880
}
28812881
} else if target.os == "ios"
28822882
|| target.os == "watchos"
@@ -2902,9 +2902,9 @@ impl Build {
29022902
"wr-cc".to_string()
29032903
}
29042904
} else if target.arch == "arm" && target.vendor == "kmc" {
2905-
format!("arm-kmc-eabi-{}", gnu)
2905+
format!("arm-kmc-eabi-{gnu}")
29062906
} else if target.arch == "aarch64" && target.vendor == "kmc" {
2907-
format!("aarch64-kmc-elf-{}", gnu)
2907+
format!("aarch64-kmc-elf-{gnu}")
29082908
} else if target.os == "nto" {
29092909
// See for details: https://github.com/rust-lang/cc-rs/pull/1319
29102910
if self.cpp {
@@ -2917,7 +2917,7 @@ impl Build {
29172917
match prefix {
29182918
Some(prefix) => {
29192919
let cc = if target.abi == "llvm" { clang } else { gnu };
2920-
format!("{}-{}", prefix, cc)
2920+
format!("{prefix}-{cc}")
29212921
}
29222922
None => default.to_string(),
29232923
}
@@ -2988,7 +2988,7 @@ impl Build {
29882988
tool.has_internal_target_arg = true;
29892989
tool.path.set_file_name(clang.trim_start_matches('-'));
29902990
tool.path.set_extension("exe");
2991-
tool.args.push(format!("--target={}", target).into());
2991+
tool.args.push(format!("--target={target}").into());
29922992

29932993
// Additionally, shell scripts for target i686-linux-android versions 16 to 24
29942994
// pass the `mstackrealign` option so we do that here as well.
@@ -3275,11 +3275,11 @@ impl Build {
32753275
// Windows use bat files so we have to be a bit more specific
32763276
if cfg!(windows) {
32773277
let mut cmd = self.cmd("cmd");
3278-
name = format!("em{}.bat", tool).into();
3278+
name = format!("em{tool}.bat").into();
32793279
cmd.arg("/c").arg(&name);
32803280
Some(cmd)
32813281
} else {
3282-
name = format!("em{}", tool).into();
3282+
name = format!("em{tool}").into();
32833283
Some(self.cmd(&name))
32843284
}
32853285
} else if target.arch == "wasm32" || target.arch == "wasm64" {
@@ -3290,7 +3290,7 @@ impl Build {
32903290
// of "llvm-ar"...
32913291
let compiler = self.get_base_compiler().ok()?;
32923292
if compiler.is_like_clang() {
3293-
name = format!("llvm-{}", tool).into();
3293+
name = format!("llvm-{tool}").into();
32943294
self.search_programs(
32953295
&mut self.cmd(&compiler.path),
32963296
&name,
@@ -3309,7 +3309,7 @@ impl Build {
33093309
Some(t) => t,
33103310
None => {
33113311
if target.os == "android" {
3312-
name = format!("llvm-{}", tool).into();
3312+
name = format!("llvm-{tool}").into();
33133313
match Command::new(&name).arg("--version").status() {
33143314
Ok(status) if status.success() => (),
33153315
_ => {
@@ -3361,15 +3361,15 @@ impl Build {
33613361
// but the OS comes bundled with a GNU-compatible variant.
33623362
//
33633363
// Use the GNU-variant to match other Unix systems.
3364-
name = format!("g{}", tool).into();
3364+
name = format!("g{tool}").into();
33653365
self.cmd(&name)
33663366
} else if target.os == "vxworks" {
3367-
name = format!("wr-{}", tool).into();
3367+
name = format!("wr-{tool}").into();
33683368
self.cmd(&name)
33693369
} else if target.os == "nto" {
33703370
// Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html
33713371
name = match target.full_arch {
3372-
"i586" => format!("ntox86-{}", tool).into(),
3372+
"i586" => format!("ntox86-{tool}").into(),
33733373
"x86" | "aarch64" | "x86_64" => {
33743374
format!("nto{}-{}", target.arch, tool).into()
33753375
}
@@ -3582,7 +3582,7 @@ impl Build {
35823582
.and_then(|path_entries| {
35833583
env::split_paths(path_entries).find_map(|path_entry| {
35843584
for prefix in prefixes {
3585-
let target_compiler = format!("{}{}{}", prefix, suffix, extension);
3585+
let target_compiler = format!("{prefix}{suffix}{extension}");
35863586
if path_entry.join(&target_compiler).exists() {
35873587
return Some(prefix);
35883588
}
@@ -3706,7 +3706,7 @@ impl Build {
37063706
// <https://github.com/rust-lang/cc-rs/pull/1215> for details.
37073707
if self.emit_rerun_if_env_changed && !provided_by_cargo(v) && v != "PATH" {
37083708
self.cargo_output
3709-
.print_metadata(&format_args!("cargo:rerun-if-env-changed={}", v));
3709+
.print_metadata(&format_args!("cargo:rerun-if-env-changed={v}"));
37103710
}
37113711
let r = env::var_os(v).map(Arc::from);
37123712
self.cargo_output.print_metadata(&format_args!(
@@ -3735,7 +3735,7 @@ impl Build {
37353735
Some(s) => Ok(s),
37363736
None => Err(Error::new(
37373737
ErrorKind::EnvVarNotFound,
3738-
format!("Environment variable {} not defined.", v),
3738+
format!("Environment variable {v} not defined."),
37393739
)),
37403740
}
37413741
}
@@ -3745,7 +3745,7 @@ impl Build {
37453745
env.to_str().map(String::from).ok_or_else(|| {
37463746
Error::new(
37473747
ErrorKind::EnvVarNotFound,
3748-
format!("Environment variable {} is not valid utf-8.", v),
3748+
format!("Environment variable {v} is not valid utf-8."),
37493749
)
37503750
})
37513751
}
@@ -3956,8 +3956,7 @@ impl Build {
39563956
// If below 10.9, we ignore it and let the SDK's target definitions handle it.
39573957
if major == 10 && minor < 9 {
39583958
self.cargo_output.print_warning(&format_args!(
3959-
"macOS deployment target ({}) too low, it will be increased",
3960-
deployment_target_ver
3959+
"macOS deployment target ({deployment_target_ver}) too low, it will be increased"
39613960
));
39623961
return None;
39633962
}
@@ -3968,8 +3967,7 @@ impl Build {
39683967
// If below 10.7, we ignore it and let the SDK's target definitions handle it.
39693968
if major < 7 {
39703969
self.cargo_output.print_warning(&format_args!(
3971-
"iOS deployment target ({}) too low, it will be increased",
3972-
deployment_target_ver
3970+
"iOS deployment target ({deployment_target_ver}) too low, it will be increased"
39733971
));
39743972
return None;
39753973
}
@@ -4140,7 +4138,7 @@ impl Default for Build {
41404138
}
41414139

41424140
fn fail(s: &str) -> ! {
4143-
eprintln!("\n\nerror occurred in cc-rs: {}\n\n", s);
4141+
eprintln!("\n\nerror occurred in cc-rs: {s}\n\n");
41444142
std::process::exit(1);
41454143
}
41464144

@@ -4202,13 +4200,13 @@ fn autodetect_android_compiler(raw_target: &str, gnu: &str, clang: &str) -> Stri
42024200
.replace("armv7", "arm")
42034201
.replace("thumbv7neon", "arm")
42044202
.replace("thumbv7", "arm");
4205-
let gnu_compiler = format!("{}-{}", target, gnu);
4206-
let clang_compiler = format!("{}-{}", target, clang);
4203+
let gnu_compiler = format!("{target}-{gnu}");
4204+
let clang_compiler = format!("{target}-{clang}");
42074205

42084206
// On Windows, the Android clang compiler is provided as a `.cmd` file instead
42094207
// of a `.exe` file. `std::process::Command` won't run `.cmd` files unless the
42104208
// `.cmd` is explicitly appended to the command name, so we do that here.
4211-
let clang_compiler_cmd = format!("{}-{}.cmd", target, clang);
4209+
let clang_compiler_cmd = format!("{target}-{clang}.cmd");
42124210

42134211
// Check if gnu compiler is present
42144212
// if not, use clang

src/tool.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ impl Tool {
261261

262262
let family = detect_family(&path, &args).unwrap_or_else(|e| {
263263
cargo_output.print_warning(&format_args!(
264-
"Compiler family detection failed due to error: {}",
265-
e
264+
"Compiler family detection failed due to error: {e}"
266265
));
267266
match path.file_name().map(OsStr::to_string_lossy) {
268267
Some(fname) if fname.contains("clang-cl") => ToolFamily::Msvc { clang_cl: true },
@@ -505,7 +504,7 @@ impl ToolFamily {
505504
ToolFamily::Gnu | ToolFamily::Clang { .. } => {
506505
cmd.push_cc_arg(
507506
dwarf_version
508-
.map_or_else(|| "-g".into(), |v| format!("-gdwarf-{}", v))
507+
.map_or_else(|| "-g".into(), |v| format!("-gdwarf-{v}"))
509508
.into(),
510509
);
511510
}

src/windows/find_tools.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,11 @@ pub fn find_vs_version() -> Result<VsVers, String> {
217217
"14.0" => Ok(VsVers::Vs14),
218218
vers => Err(format!(
219219
"\n\n\
220-
unsupported or unknown VisualStudio version: {}\n\
220+
unsupported or unknown VisualStudio version: {vers}\n\
221221
if another version is installed consider running \
222222
the appropriate vcvars script before building this \
223223
crate\n\
224-
",
225-
vers
224+
"
226225
)),
227226
},
228227
_ => {

0 commit comments

Comments
 (0)