From 54edf321438137e611649c6528aa7d637afe9dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 26 Oct 2018 16:23:02 +0200 Subject: [PATCH] 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. --- src/bootstrap/compile.rs | 10 +++++----- src/bootstrap/flags.rs | 19 +++++++++---------- src/bootstrap/lib.rs | 8 ++++---- src/bootstrap/sanity.rs | 2 +- src/bootstrap/test.rs | 20 ++++++++++---------- src/bootstrap/tool.rs | 8 ++++---- 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 69d45acdedaf9..d009d9645c35a 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -69,7 +69,7 @@ impl Step for Std { if builder.config.keep_stage.contains(&compiler.stage) { builder.info("Warning: Using a potentially old libstd. This may not behave well."); builder.ensure(StdLink { - compiler: compiler, + compiler, target_compiler: compiler, target, }); @@ -358,7 +358,7 @@ impl Step for Test { if builder.config.keep_stage.contains(&compiler.stage) { builder.info("Warning: Using a potentially old libtest. This may not behave well."); builder.ensure(TestLink { - compiler: compiler, + compiler, target_compiler: compiler, target, }); @@ -480,7 +480,7 @@ impl Step for Rustc { if builder.config.keep_stage.contains(&compiler.stage) { builder.info("Warning: Using a potentially old librustc. This may not behave well."); builder.ensure(RustcLink { - compiler: compiler, + compiler, target_compiler: compiler, target, }); @@ -816,8 +816,8 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder, let filename = file.file_name().unwrap().to_str().unwrap(); // change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so` let target_filename = { - let dash = filename.find("-").unwrap(); - let dot = filename.find(".").unwrap(); + let dash = filename.find('-').unwrap(); + let dot = filename.find('.').unwrap(); format!("{}-{}{}", &filename[..dash], backend, diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 2084b8bdb65ff..1211d485d1c12 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -93,8 +93,7 @@ impl Default for Subcommand { impl Flags { pub fn parse(args: &[String]) -> Flags { let mut extra_help = String::new(); - let mut subcommand_help = format!( - "\ + let mut subcommand_help = String::from("\ Usage: x.py [options] [...] Subcommands: @@ -365,8 +364,8 @@ Arguments: } let cmd = match subcommand.as_str() { - "build" => Subcommand::Build { paths: paths }, - "check" => Subcommand::Check { paths: paths }, + "build" => Subcommand::Build { paths }, + "check" => Subcommand::Check { paths }, "test" => Subcommand::Test { paths, bless: matches.opt_present("bless"), @@ -386,9 +385,9 @@ Arguments: paths, test_args: matches.opt_strs("test-args"), }, - "doc" => Subcommand::Doc { paths: paths }, + "doc" => Subcommand::Doc { paths }, "clean" => { - if paths.len() > 0 { + if !paths.is_empty() { println!("\nclean does not take a path argument\n"); usage(1, &opts, &subcommand_help, &extra_help); } @@ -413,11 +412,11 @@ Arguments: keep_stage: matches.opt_strs("keep-stage") .into_iter().map(|j| j.parse().unwrap()) .collect(), - host: split(matches.opt_strs("host")) + host: split(&matches.opt_strs("host")) .into_iter() .map(|x| INTERNER.intern_string(x)) .collect::>(), - target: split(matches.opt_strs("target")) + target: split(&matches.opt_strs("target")) .into_iter() .map(|x| INTERNER.intern_string(x)) .collect::>(), @@ -425,7 +424,7 @@ Arguments: jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()), cmd, incremental: matches.opt_present("incremental"), - exclude: split(matches.opt_strs("exclude")) + exclude: split(&matches.opt_strs("exclude")) .into_iter() .map(|p| p.into()) .collect::>(), @@ -488,7 +487,7 @@ impl Subcommand { } } -fn split(s: Vec) -> Vec { +fn split(s: &[String]) -> Vec { s.iter() .flat_map(|s| s.split(',')) .map(|s| s.to_string()) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 4e26c98a62759..d57b125da4023 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -768,7 +768,7 @@ impl Build { let sha = self.rust_info.sha().expect("failed to find sha"); format!("/rustc/{}", sha) } - GitRepo::Llvm => format!("/rustc/llvm"), + GitRepo::Llvm => String::from("/rustc/llvm"), }; Some(format!("{}={}", self.src.display(), path)) } @@ -783,7 +783,7 @@ impl Build { fn cflags(&self, target: Interned, which: GitRepo) -> Vec { // Filter out -O and /O (the optimization flags) that we picked up from // cc-rs because the build scripts will determine that for themselves. - let mut base = self.cc[&target].args().iter() + let mut base: Vec = self.cc[&target].args().iter() .map(|s| s.to_string_lossy().into_owned()) .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) .collect::>(); @@ -806,10 +806,10 @@ impl Build { if let Some(map) = self.debuginfo_map(which) { let cc = self.cc(target); 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") { base.push("-Xclang".into()); - base.push(format!("-fdebug-prefix-map={}", map).into()); + base.push(format!("-fdebug-prefix-map={}", map)); } } base diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 724cb5841f48f..2eb11b06e4e08 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -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 // being unable to identify the files properly. See // 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 '\"'"); } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index fe04a91011ee5..9edfaafa905bb 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -521,7 +521,7 @@ impl Step for RustdocTheme { fn make_run(run: RunConfig) { 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) { @@ -584,9 +584,9 @@ impl Step for RustdocJS { }); builder.run(&mut command); } else { - builder.info(&format!( + builder.info( "No nodejs found, skipping \"src/test/rustdoc-js\" tests" - )); + ); } } } @@ -653,7 +653,7 @@ impl Step for Tidy { } let _folder = builder.fold_output(|| "tidy"); - builder.info(&format!("tidy check")); + builder.info("tidy check"); try_run(builder, &mut cmd); } @@ -1168,9 +1168,9 @@ impl Step for Compiletest { } } 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" - )); + ); return; } @@ -1692,10 +1692,10 @@ impl Step for Crate { // The javascript shim implements the syscall interface so that test // output can be correctly reported. if !builder.config.wasm_syscall { - builder.info(&format!( + builder.info( "Libstd was built without `wasm_syscall` feature enabled: \ test output may not be visible." - )); + ); } // 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 fn run(self, builder: &Builder) { - builder.info(&format!("Distcheck")); + builder.info("Distcheck"); let dir = builder.out.join("tmp").join("distcheck"); let _ = fs::remove_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 - builder.info(&format!("Distcheck rust-src")); + builder.info("Distcheck rust-src"); let dir = builder.out.join("tmp").join("distcheck-src"); let _ = fs::remove_dir_all(&dir); t!(fs::create_dir_all(&dir)); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 15d27c613423a..978e3602e7dbc 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -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 \ typically means that something was recompiled because \ a transitive dependency has different features activated \ @@ -170,7 +170,7 @@ impl Step for ToolBuild { println!(" `{}` additionally enabled features {:?} at {:?}", prev.0, &prev_features - &cur_features, prev.1); } - println!(""); + println!(); println!("to fix this you will probably want to edit the local \ src/tools/rustc-workspace-hack/Cargo.toml crate, as \ that will update the dependency graph to ensure that \ @@ -188,7 +188,7 @@ impl Step for ToolBuild { if !is_optional_tool { exit(1); } else { - return None; + None } } else { 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() { cargo.env("CFG_COMMIT_DATE", date); } - if features.len() > 0 { + if !features.is_empty() { cargo.arg("--features").arg(&features.join(", ")); } cargo