Skip to content

Commit

Permalink
Auto merge of #114066 - matthiaskrgr:fmt_args_inline_bootstrap, r=Waf…
Browse files Browse the repository at this point in the history
…fleLapkin

bootstrap: inline format!() args (0)

r? `@WaffleLapkin`
  • Loading branch information
bors committed Jul 30, 2023
2 parents 4c9ac1e + a0503a8 commit 483ef5f
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 174 deletions.
8 changes: 4 additions & 4 deletions src/bootstrap/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() {
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{}", suggestion);
println!("{suggestion}");
}

let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
Expand All @@ -80,7 +80,7 @@ fn main() {
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{}", suggestion);
println!("{suggestion}");
}

// Give a warning if the pre-commit script is in pre-commit and not pre-push.
Expand All @@ -107,13 +107,13 @@ fn check_version(config: &Config) -> Option<String> {
let suggestion = if let Some(seen) = config.changelog_seen {
if seen != VERSION {
msg.push_str("warning: there have been changes to x.py since you last updated.\n");
format!("update `config.toml` to use `changelog-seen = {}` instead", VERSION)
format!("update `config.toml` to use `changelog-seen = {VERSION}` instead")
} else {
return None;
}
} else {
msg.push_str("warning: x.py has made several changes recently you may want to look at\n");
format!("add `changelog-seen = {}` at the top of `config.toml`", VERSION)
format!("add `changelog-seen = {VERSION}` at the top of `config.toml`")
};

msg.push_str("help: consider looking at the changes in `src/bootstrap/CHANGELOG.md`\n");
Expand Down
23 changes: 11 additions & 12 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn main() {

// Override linker if necessary.
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
cmd.arg(format!("-Clinker={}", host_linker));
cmd.arg(format!("-Clinker={host_linker}"));
}
if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
cmd.arg("-Clink-args=-fuse-ld=lld");
Expand Down Expand Up @@ -206,11 +206,11 @@ fn main() {
env::vars().filter(|(k, _)| k.starts_with("RUST") || k.starts_with("CARGO"));
let prefix = if is_test { "[RUSTC-SHIM] rustc --test" } else { "[RUSTC-SHIM] rustc" };
let prefix = match crate_name {
Some(crate_name) => format!("{} {}", prefix, crate_name),
Some(crate_name) => format!("{prefix} {crate_name}"),
None => prefix.to_string(),
};
for (i, (k, v)) in rust_env_vars.enumerate() {
eprintln!("{} env[{}]: {:?}={:?}", prefix, i, k, v);
eprintln!("{prefix} env[{i}]: {k:?}={v:?}");
}
eprintln!("{} working directory: {}", prefix, env::current_dir().unwrap().display());
eprintln!(
Expand All @@ -220,13 +220,13 @@ fn main() {
env::join_paths(&dylib_path).unwrap(),
cmd,
);
eprintln!("{} sysroot: {:?}", prefix, sysroot);
eprintln!("{} libdir: {:?}", prefix, libdir);
eprintln!("{prefix} sysroot: {sysroot:?}");
eprintln!("{prefix} libdir: {libdir:?}");
}

let start = Instant::now();
let (child, status) = {
let errmsg = format!("\nFailed to run:\n{:?}\n-------------", cmd);
let errmsg = format!("\nFailed to run:\n{cmd:?}\n-------------");
let mut child = cmd.spawn().expect(&errmsg);
let status = child.wait().expect(&errmsg);
(child, status)
Expand Down Expand Up @@ -259,7 +259,7 @@ fn main() {
// should run on success, after this block.
}
if verbose > 0 {
println!("\nDid not run successfully: {}\n{:?}\n-------------", status, cmd);
println!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
}

if let Some(mut on_fail) = on_fail {
Expand All @@ -271,7 +271,7 @@ fn main() {
match status.code() {
Some(i) => std::process::exit(i),
None => {
eprintln!("rustc exited with {}", status);
eprintln!("rustc exited with {status}");
std::process::exit(0xfe);
}
}
Expand Down Expand Up @@ -396,21 +396,20 @@ fn format_rusage_data(_child: Child) -> Option<String> {
let minflt = rusage.ru_minflt;
let majflt = rusage.ru_majflt;
if minflt != 0 || majflt != 0 {
init_str.push_str(&format!(" page reclaims: {} page faults: {}", minflt, majflt));
init_str.push_str(&format!(" page reclaims: {minflt} page faults: {majflt}"));
}

let inblock = rusage.ru_inblock;
let oublock = rusage.ru_oublock;
if inblock != 0 || oublock != 0 {
init_str.push_str(&format!(" fs block inputs: {} fs block outputs: {}", inblock, oublock));
init_str.push_str(&format!(" fs block inputs: {inblock} fs block outputs: {oublock}"));
}

let nvcsw = rusage.ru_nvcsw;
let nivcsw = rusage.ru_nivcsw;
if nvcsw != 0 || nivcsw != 0 {
init_str.push_str(&format!(
" voluntary ctxt switches: {} involuntary ctxt switches: {}",
nvcsw, nivcsw
" voluntary ctxt switches: {nvcsw} involuntary ctxt switches: {nivcsw}"
));
}

Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() {
}
if let Ok(no_threads) = env::var("RUSTDOC_LLD_NO_THREADS") {
cmd.arg("-Clink-arg=-fuse-ld=lld");
cmd.arg(format!("-Clink-arg=-Wl,{}", no_threads));
cmd.arg(format!("-Clink-arg=-Wl,{no_threads}"));
}
// Cargo doesn't pass RUSTDOCFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
Expand All @@ -82,12 +82,12 @@ fn main() {
env::join_paths(&dylib_path).unwrap(),
cmd,
);
eprintln!("sysroot: {:?}", sysroot);
eprintln!("libdir: {:?}", libdir);
eprintln!("sysroot: {sysroot:?}");
eprintln!("libdir: {libdir:?}");
}

std::process::exit(match cmd.status() {
Ok(s) => s.code().unwrap_or(1),
Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
Err(e) => panic!("\n\nfailed to run {cmd:?}: {e}\n\n"),
})
}
2 changes: 1 addition & 1 deletion src/bootstrap/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use std::env;
fn main() {
let host = env::var("HOST").unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-env=BUILD_TRIPLE={}", host);
println!("cargo:rustc-env=BUILD_TRIPLE={host}");
}
39 changes: 19 additions & 20 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl StepDescription {
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
if builder.config.exclude.iter().any(|e| pathset.has(&e, builder.kind)) {
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
println!("Skipping {:?} because it is excluded", pathset);
println!("Skipping {pathset:?} because it is excluded");
}
return true;
}
Expand Down Expand Up @@ -473,8 +473,7 @@ impl<'a> ShouldRun<'a> {
// `compiler` and `library` folders respectively.
assert!(
self.kind == Kind::Setup || !self.builder.src.join(alias).exists(),
"use `builder.path()` for real paths: {}",
alias
"use `builder.path()` for real paths: {alias}"
);
self.paths.insert(PathSet::Set(
std::iter::once(TaskPath { path: alias.into(), kind: Some(self.kind) }).collect(),
Expand Down Expand Up @@ -1283,7 +1282,7 @@ impl<'a> Builder<'a> {
out_dir.join(target.triple).join("doc")
}
}
_ => panic!("doc mode {:?} not expected", mode),
_ => panic!("doc mode {mode:?} not expected"),
};
let rustdoc = self.rustdoc(compiler);
self.clear_if_dirty(&my_out, &rustdoc);
Expand Down Expand Up @@ -1637,15 +1636,15 @@ impl<'a> Builder<'a> {
// so. Note that this is definitely a hack, and we should likely
// flesh out rpath support more fully in the future.
rustflags.arg("-Zosx-rpath-install-name");
Some(format!("-Wl,-rpath,@loader_path/../{}", libdir))
Some(format!("-Wl,-rpath,@loader_path/../{libdir}"))
} else if !target.contains("windows") && !target.contains("aix") {
rustflags.arg("-Clink-args=-Wl,-z,origin");
Some(format!("-Wl,-rpath,$ORIGIN/../{}", libdir))
Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}"))
} else {
None
};
if let Some(rpath) = rpath {
rustflags.arg(&format!("-Clink-args={}", rpath));
rustflags.arg(&format!("-Clink-args={rpath}"));
}
}

Expand All @@ -1659,7 +1658,7 @@ impl<'a> Builder<'a> {

if let Some(target_linker) = self.linker(target) {
let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
cargo.env(&format!("CARGO_TARGET_{target}_LINKER"), target_linker);
}
if self.is_fuse_ld_lld(target) {
rustflags.arg("-Clink-args=-fuse-ld=lld");
Expand Down Expand Up @@ -1895,24 +1894,24 @@ impl<'a> Builder<'a> {
};
let triple_underscored = target.triple.replace("-", "_");
let cc = ccacheify(&self.cc(target));
cargo.env(format!("CC_{}", triple_underscored), &cc);
cargo.env(format!("CC_{triple_underscored}"), &cc);

let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
cargo.env(format!("CFLAGS_{}", triple_underscored), &cflags);
cargo.env(format!("CFLAGS_{triple_underscored}"), &cflags);

if let Some(ar) = self.ar(target) {
let ranlib = format!("{} s", ar.display());
cargo
.env(format!("AR_{}", triple_underscored), ar)
.env(format!("RANLIB_{}", triple_underscored), ranlib);
.env(format!("AR_{triple_underscored}"), ar)
.env(format!("RANLIB_{triple_underscored}"), ranlib);
}

if let Ok(cxx) = self.cxx(target) {
let cxx = ccacheify(&cxx);
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
cargo
.env(format!("CXX_{}", triple_underscored), &cxx)
.env(format!("CXXFLAGS_{}", triple_underscored), cxxflags);
.env(format!("CXX_{triple_underscored}"), &cxx)
.env(format!("CXXFLAGS_{triple_underscored}"), cxxflags);
}
}

Expand Down Expand Up @@ -2025,15 +2024,15 @@ impl<'a> Builder<'a> {
if let Some(limit) = limit {
if stage == 0 || self.config.default_codegen_backend().unwrap_or_default() == "llvm"
{
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit));
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}"));
}
}
}

if matches!(mode, Mode::Std) {
if let Some(mir_opt_level) = self.config.rust_validate_mir_opts {
rustflags.arg("-Zvalidate-mir");
rustflags.arg(&format!("-Zmir-opt-level={}", mir_opt_level));
rustflags.arg(&format!("-Zmir-opt-level={mir_opt_level}"));
}
// Always enable inlining MIR when building the standard library.
// Without this flag, MIR inlining is disabled when incremental compilation is enabled.
Expand Down Expand Up @@ -2065,9 +2064,9 @@ impl<'a> Builder<'a> {
continue;
}
let mut out = String::new();
out += &format!("\n\nCycle in build detected when adding {:?}\n", step);
out += &format!("\n\nCycle in build detected when adding {step:?}\n");
for el in stack.iter().rev() {
out += &format!("\t{:?}\n", el);
out += &format!("\t{el:?}\n");
}
panic!("{}", out);
}
Expand All @@ -2094,7 +2093,7 @@ impl<'a> Builder<'a> {
};

if self.config.print_step_timings && !self.config.dry_run() {
let step_string = format!("{:?}", step);
let step_string = format!("{step:?}");
let brace_index = step_string.find("{").unwrap_or(0);
let type_string = type_name::<S>();
println!(
Expand Down Expand Up @@ -2174,7 +2173,7 @@ impl<'a> Builder<'a> {
let path = path.as_ref();
self.info(&format!("Opening doc {}", path.display()));
if let Err(err) = opener::open(path) {
self.info(&format!("{}\n", err));
self.info(&format!("{err}\n"));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: &U = &*self;
f.write_fmt(format_args!("{:?}", s))
f.write_fmt(format_args!("{s:?}"))
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ impl Cache {
.or_insert_with(|| Box::new(HashMap::<S, S::Output>::new()))
.downcast_mut::<HashMap<S, S::Output>>()
.expect("invalid type mapped");
assert!(!stepcache.contains_key(&step), "processing {:?} a second time", step);
assert!(!stepcache.contains_key(&step), "processing {step:?} a second time");
stepcache.insert(step, value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn set_compiler(
'0'..='6' => {}
_ => return,
}
let alternative = format!("e{}", gnu_compiler);
let alternative = format!("e{gnu_compiler}");
if Command::new(&alternative).output().is_ok() {
cfg.compiler(alternative);
}
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl Step for CodegenBackend {
);
cargo
.arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{}/Cargo.toml", backend)));
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);

let _guard = builder.msg_check(&backend, target);
Expand Down Expand Up @@ -525,5 +525,5 @@ fn codegen_backend_stamp(
) -> PathBuf {
builder
.cargo_out(compiler, Mode::Codegen, target)
.join(format!(".librustc_codegen_{}-check.stamp", backend))
.join(format!(".librustc_codegen_{backend}-check.stamp"))
}
Loading

0 comments on commit 483ef5f

Please sign in to comment.