1
Fork 0

Rollup merge of #55391 - matthiaskrgr:bootstrap_cleanup, r=oli-obk

bootstrap: clean up a few clippy findings

remove useless format!()s
remove redundant field names in a few struct initializations
pass slice instead of a vector to a function
use is_empty() instead of comparisons to .len()

No functional change intended.
This commit is contained in:
kennytm 2018-10-26 23:10:38 +08:00
commit eb29530224
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
6 changed files with 33 additions and 34 deletions

View file

@ -69,7 +69,7 @@ impl Step for Std {
if builder.config.keep_stage.contains(&compiler.stage) { if builder.config.keep_stage.contains(&compiler.stage) {
builder.info("Warning: Using a potentially old libstd. This may not behave well."); builder.info("Warning: Using a potentially old libstd. This may not behave well.");
builder.ensure(StdLink { builder.ensure(StdLink {
compiler: compiler, compiler,
target_compiler: compiler, target_compiler: compiler,
target, target,
}); });
@ -358,7 +358,7 @@ impl Step for Test {
if builder.config.keep_stage.contains(&compiler.stage) { if builder.config.keep_stage.contains(&compiler.stage) {
builder.info("Warning: Using a potentially old libtest. This may not behave well."); builder.info("Warning: Using a potentially old libtest. This may not behave well.");
builder.ensure(TestLink { builder.ensure(TestLink {
compiler: compiler, compiler,
target_compiler: compiler, target_compiler: compiler,
target, target,
}); });
@ -480,7 +480,7 @@ impl Step for Rustc {
if builder.config.keep_stage.contains(&compiler.stage) { if builder.config.keep_stage.contains(&compiler.stage) {
builder.info("Warning: Using a potentially old librustc. This may not behave well."); builder.info("Warning: Using a potentially old librustc. This may not behave well.");
builder.ensure(RustcLink { builder.ensure(RustcLink {
compiler: compiler, compiler,
target_compiler: compiler, target_compiler: compiler,
target, target,
}); });
@ -816,8 +816,8 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
let filename = file.file_name().unwrap().to_str().unwrap(); let filename = file.file_name().unwrap().to_str().unwrap();
// change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so` // change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so`
let target_filename = { let target_filename = {
let dash = filename.find("-").unwrap(); let dash = filename.find('-').unwrap();
let dot = filename.find(".").unwrap(); let dot = filename.find('.').unwrap();
format!("{}-{}{}", format!("{}-{}{}",
&filename[..dash], &filename[..dash],
backend, backend,

View file

@ -93,8 +93,7 @@ impl Default for Subcommand {
impl Flags { impl Flags {
pub fn parse(args: &[String]) -> Flags { pub fn parse(args: &[String]) -> Flags {
let mut extra_help = String::new(); let mut extra_help = String::new();
let mut subcommand_help = format!( let mut subcommand_help = String::from("\
"\
Usage: x.py <subcommand> [options] [<paths>...] Usage: x.py <subcommand> [options] [<paths>...]
Subcommands: Subcommands:
@ -365,8 +364,8 @@ Arguments:
} }
let cmd = match subcommand.as_str() { let cmd = match subcommand.as_str() {
"build" => Subcommand::Build { paths: paths }, "build" => Subcommand::Build { paths },
"check" => Subcommand::Check { paths: paths }, "check" => Subcommand::Check { paths },
"test" => Subcommand::Test { "test" => Subcommand::Test {
paths, paths,
bless: matches.opt_present("bless"), bless: matches.opt_present("bless"),
@ -386,9 +385,9 @@ Arguments:
paths, paths,
test_args: matches.opt_strs("test-args"), test_args: matches.opt_strs("test-args"),
}, },
"doc" => Subcommand::Doc { paths: paths }, "doc" => Subcommand::Doc { paths },
"clean" => { "clean" => {
if paths.len() > 0 { if !paths.is_empty() {
println!("\nclean does not take a path argument\n"); println!("\nclean does not take a path argument\n");
usage(1, &opts, &subcommand_help, &extra_help); usage(1, &opts, &subcommand_help, &extra_help);
} }
@ -413,11 +412,11 @@ Arguments:
keep_stage: matches.opt_strs("keep-stage") keep_stage: matches.opt_strs("keep-stage")
.into_iter().map(|j| j.parse().unwrap()) .into_iter().map(|j| j.parse().unwrap())
.collect(), .collect(),
host: split(matches.opt_strs("host")) host: split(&matches.opt_strs("host"))
.into_iter() .into_iter()
.map(|x| INTERNER.intern_string(x)) .map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
target: split(matches.opt_strs("target")) target: split(&matches.opt_strs("target"))
.into_iter() .into_iter()
.map(|x| INTERNER.intern_string(x)) .map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
@ -425,7 +424,7 @@ Arguments:
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()), jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
cmd, cmd,
incremental: matches.opt_present("incremental"), incremental: matches.opt_present("incremental"),
exclude: split(matches.opt_strs("exclude")) exclude: split(&matches.opt_strs("exclude"))
.into_iter() .into_iter()
.map(|p| p.into()) .map(|p| p.into())
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
@ -488,7 +487,7 @@ impl Subcommand {
} }
} }
fn split(s: Vec<String>) -> Vec<String> { fn split(s: &[String]) -> Vec<String> {
s.iter() s.iter()
.flat_map(|s| s.split(',')) .flat_map(|s| s.split(','))
.map(|s| s.to_string()) .map(|s| s.to_string())

View file

@ -768,7 +768,7 @@ impl Build {
let sha = self.rust_sha().unwrap_or(channel::CFG_RELEASE_NUM); let sha = self.rust_sha().unwrap_or(channel::CFG_RELEASE_NUM);
format!("/rustc/{}", sha) format!("/rustc/{}", sha)
} }
GitRepo::Llvm => format!("/rustc/llvm"), GitRepo::Llvm => String::from("/rustc/llvm"),
}; };
Some(format!("{}={}", self.src.display(), path)) Some(format!("{}={}", self.src.display(), path))
} }
@ -783,7 +783,7 @@ impl Build {
fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> { fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> {
// Filter out -O and /O (the optimization flags) that we picked up from // Filter out -O and /O (the optimization flags) that we picked up from
// cc-rs because the build scripts will determine that for themselves. // cc-rs because the build scripts will determine that for themselves.
let mut base = self.cc[&target].args().iter() let mut base: Vec<String> = self.cc[&target].args().iter()
.map(|s| s.to_string_lossy().into_owned()) .map(|s| s.to_string_lossy().into_owned())
.filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) .filter(|s| !s.starts_with("-O") && !s.starts_with("/O"))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -806,10 +806,10 @@ impl Build {
if let Some(map) = self.debuginfo_map(which) { if let Some(map) = self.debuginfo_map(which) {
let cc = self.cc(target); let cc = self.cc(target);
if cc.ends_with("clang") || cc.ends_with("gcc") { if cc.ends_with("clang") || cc.ends_with("gcc") {
base.push(format!("-fdebug-prefix-map={}", map).into()); base.push(format!("-fdebug-prefix-map={}", map));
} else if cc.ends_with("clang-cl.exe") { } else if cc.ends_with("clang-cl.exe") {
base.push("-Xclang".into()); base.push("-Xclang".into());
base.push(format!("-fdebug-prefix-map={}", map).into()); base.push(format!("-fdebug-prefix-map={}", map));
} }
} }
base base

View file

@ -74,7 +74,7 @@ pub fn check(build: &mut Build) {
// one is present as part of the PATH then that can lead to the system // one is present as part of the PATH then that can lead to the system
// being unable to identify the files properly. See // being unable to identify the files properly. See
// https://github.com/rust-lang/rust/issues/34959 for more details. // https://github.com/rust-lang/rust/issues/34959 for more details.
if cfg!(windows) && path.to_string_lossy().contains("\"") { if cfg!(windows) && path.to_string_lossy().contains('\"') {
panic!("PATH contains invalid character '\"'"); panic!("PATH contains invalid character '\"'");
} }

View file

@ -521,7 +521,7 @@ impl Step for RustdocTheme {
fn make_run(run: RunConfig) { fn make_run(run: RunConfig) {
let compiler = run.builder.compiler(run.builder.top_stage, run.host); let compiler = run.builder.compiler(run.builder.top_stage, run.host);
run.builder.ensure(RustdocTheme { compiler: compiler }); run.builder.ensure(RustdocTheme { compiler });
} }
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
@ -584,9 +584,9 @@ impl Step for RustdocJS {
}); });
builder.run(&mut command); builder.run(&mut command);
} else { } else {
builder.info(&format!( builder.info(
"No nodejs found, skipping \"src/test/rustdoc-js\" tests" "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
)); );
} }
} }
} }
@ -653,7 +653,7 @@ impl Step for Tidy {
} }
let _folder = builder.fold_output(|| "tidy"); let _folder = builder.fold_output(|| "tidy");
builder.info(&format!("tidy check")); builder.info("tidy check");
try_run(builder, &mut cmd); try_run(builder, &mut cmd);
} }
@ -1168,9 +1168,9 @@ impl Step for Compiletest {
} }
} }
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled { if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
builder.info(&format!( builder.info(
"Ignoring run-make test suite as they generally don't work without LLVM" "Ignoring run-make test suite as they generally don't work without LLVM"
)); );
return; return;
} }
@ -1692,10 +1692,10 @@ impl Step for Crate {
// The javascript shim implements the syscall interface so that test // The javascript shim implements the syscall interface so that test
// output can be correctly reported. // output can be correctly reported.
if !builder.config.wasm_syscall { if !builder.config.wasm_syscall {
builder.info(&format!( builder.info(
"Libstd was built without `wasm_syscall` feature enabled: \ "Libstd was built without `wasm_syscall` feature enabled: \
test output may not be visible." test output may not be visible."
)); );
} }
// On the wasm32-unknown-unknown target we're using LTO which is // On the wasm32-unknown-unknown target we're using LTO which is
@ -1891,7 +1891,7 @@ impl Step for Distcheck {
/// Run "distcheck", a 'make check' from a tarball /// Run "distcheck", a 'make check' from a tarball
fn run(self, builder: &Builder) { fn run(self, builder: &Builder) {
builder.info(&format!("Distcheck")); builder.info("Distcheck");
let dir = builder.out.join("tmp").join("distcheck"); let dir = builder.out.join("tmp").join("distcheck");
let _ = fs::remove_dir_all(&dir); let _ = fs::remove_dir_all(&dir);
t!(fs::create_dir_all(&dir)); t!(fs::create_dir_all(&dir));
@ -1919,7 +1919,7 @@ impl Step for Distcheck {
); );
// Now make sure that rust-src has all of libstd's dependencies // Now make sure that rust-src has all of libstd's dependencies
builder.info(&format!("Distcheck rust-src")); builder.info("Distcheck rust-src");
let dir = builder.out.join("tmp").join("distcheck-src"); let dir = builder.out.join("tmp").join("distcheck-src");
let _ = fs::remove_dir_all(&dir); let _ = fs::remove_dir_all(&dir);
t!(fs::create_dir_all(&dir)); t!(fs::create_dir_all(&dir));

View file

@ -148,7 +148,7 @@ impl Step for ToolBuild {
} }
}); });
if is_expected && duplicates.len() != 0 { if is_expected && !duplicates.is_empty() {
println!("duplicate artfacts found when compiling a tool, this \ println!("duplicate artfacts found when compiling a tool, this \
typically means that something was recompiled because \ typically means that something was recompiled because \
a transitive dependency has different features activated \ a transitive dependency has different features activated \
@ -170,7 +170,7 @@ impl Step for ToolBuild {
println!(" `{}` additionally enabled features {:?} at {:?}", println!(" `{}` additionally enabled features {:?} at {:?}",
prev.0, &prev_features - &cur_features, prev.1); prev.0, &prev_features - &cur_features, prev.1);
} }
println!(""); println!();
println!("to fix this you will probably want to edit the local \ println!("to fix this you will probably want to edit the local \
src/tools/rustc-workspace-hack/Cargo.toml crate, as \ src/tools/rustc-workspace-hack/Cargo.toml crate, as \
that will update the dependency graph to ensure that \ that will update the dependency graph to ensure that \
@ -188,7 +188,7 @@ impl Step for ToolBuild {
if !is_optional_tool { if !is_optional_tool {
exit(1); exit(1);
} else { } else {
return None; None
} }
} else { } else {
let cargo_out = builder.cargo_out(compiler, self.mode, target) let cargo_out = builder.cargo_out(compiler, self.mode, target)
@ -251,7 +251,7 @@ pub fn prepare_tool_cargo(
if let Some(date) = info.commit_date() { if let Some(date) = info.commit_date() {
cargo.env("CFG_COMMIT_DATE", date); cargo.env("CFG_COMMIT_DATE", date);
} }
if features.len() > 0 { if !features.is_empty() {
cargo.arg("--features").arg(&features.join(", ")); cargo.arg("--features").arg(&features.join(", "));
} }
cargo cargo