Skip to content

Commit

Permalink
Rollup merge of #55391 - matthiaskrgr:bootstrap_cleanup, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennytm committed Oct 26, 2018
2 parents 5a16579 + 54edf32 commit eb29530
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 9 additions & 10 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <subcommand> [options] [<paths>...]
Subcommands:
Expand Down Expand Up @@ -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"),
Expand All @@ -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);
}
Expand All @@ -413,19 +412,19 @@ 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::<Vec<_>>(),
target: split(matches.opt_strs("target"))
target: split(&matches.opt_strs("target"))
.into_iter()
.map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(),
config: cfg_file,
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::<Vec<_>>(),
Expand Down Expand Up @@ -488,7 +487,7 @@ impl Subcommand {
}
}

fn split(s: Vec<String>) -> Vec<String> {
fn split(s: &[String]) -> Vec<String> {
s.iter()
.flat_map(|s| s.split(','))
.map(|s| s.to_string())
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl Build {
let sha = self.rust_sha().unwrap_or(channel::CFG_RELEASE_NUM);
format!("/rustc/{}", sha)
}
GitRepo::Llvm => format!("/rustc/llvm"),
GitRepo::Llvm => String::from("/rustc/llvm"),
};
Some(format!("{}={}", self.src.display(), path))
}
Expand All @@ -783,7 +783,7 @@ impl Build {
fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> {
// 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<String> = self.cc[&target].args().iter()
.map(|s| s.to_string_lossy().into_owned())
.filter(|s| !s.starts_with("-O") && !s.starts_with("/O"))
.collect::<Vec<_>>();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '\"'");
}

Expand Down
20 changes: 10 additions & 10 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
));
);
}
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb29530

Please sign in to comment.