Skip to content

Commit 4d6e2d8

Browse files
authored
Rollup merge of rust-lang#68805 - matthiaskrgr:cleanup_bootstrap, r=Mark-Simulacrum
bootstrap: fix clippy warnings r? @oli-obk
2 parents 48ea0fa + 5f979e9 commit 4d6e2d8

17 files changed

+40
-57
lines changed

src/bootstrap/bin/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
};
4848
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
4949
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
50-
let on_fail = env::var_os("RUSTC_ON_FAIL").map(|of| Command::new(of));
50+
let on_fail = env::var_os("RUSTC_ON_FAIL").map(Command::new);
5151

5252
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
5353
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
@@ -64,7 +64,7 @@ fn main() {
6464
if let Some(crate_name) = crate_name {
6565
if let Some(target) = env::var_os("RUSTC_TIME") {
6666
if target == "all"
67-
|| target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name)
67+
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
6868
{
6969
cmd.arg("-Ztime");
7070
}
@@ -189,7 +189,7 @@ fn main() {
189189
crate_name,
190190
is_test,
191191
dur.as_secs(),
192-
dur.subsec_nanos() / 1_000_000
192+
dur.subsec_millis()
193193
);
194194

195195
match status.code() {

src/bootstrap/bin/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
}
6262

6363
// Needed to be able to run all rustdoc tests.
64-
if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") {
64+
if env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES").is_some() {
6565
// This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
6666
if !has_unstable {
6767
cmd.arg("-Z").arg("unstable-options");

src/bootstrap/builder.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,15 @@ impl<'a> Builder<'a> {
510510
Subcommand::Format { .. } | Subcommand::Clean { .. } => panic!(),
511511
};
512512

513-
let builder = Builder {
513+
Builder {
514514
build,
515515
top_stage: build.config.stage.unwrap_or(2),
516516
kind,
517517
cache: Cache::new(),
518518
stack: RefCell::new(Vec::new()),
519519
time_spent_on_dependencies: Cell::new(Duration::new(0, 0)),
520520
paths: paths.to_owned(),
521-
};
522-
523-
builder
521+
}
524522
}
525523

526524
pub fn execute_cli(&self) {
@@ -753,13 +751,12 @@ impl<'a> Builder<'a> {
753751
cargo.env("RUST_CHECK", "1");
754752
}
755753

756-
let stage;
757-
if compiler.stage == 0 && self.local_rebuild {
754+
let stage = if compiler.stage == 0 && self.local_rebuild {
758755
// Assume the local-rebuild rustc already has stage1 features.
759-
stage = 1;
756+
1
760757
} else {
761-
stage = compiler.stage;
762-
}
758+
compiler.stage
759+
};
763760

764761
let mut rustflags = Rustflags::new(&target);
765762
if stage != 0 {
@@ -1252,12 +1249,7 @@ impl<'a> Builder<'a> {
12521249
};
12531250

12541251
if self.config.print_step_timings && dur > Duration::from_millis(100) {
1255-
println!(
1256-
"[TIMING] {:?} -- {}.{:03}",
1257-
step,
1258-
dur.as_secs(),
1259-
dur.subsec_nanos() / 1_000_000
1260-
);
1252+
println!("[TIMING] {:?} -- {}.{:03}", step, dur.as_secs(), dur.subsec_millis());
12611253
}
12621254

12631255
{
@@ -1302,7 +1294,7 @@ impl Rustflags {
13021294

13031295
fn arg(&mut self, arg: &str) -> &mut Self {
13041296
assert_eq!(arg.split_whitespace().count(), 1);
1305-
if self.0.len() > 0 {
1297+
if !self.0.is_empty() {
13061298
self.0.push_str(" ");
13071299
}
13081300
self.0.push_str(arg);

src/bootstrap/builder/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ fn configure(host: &[&str], target: &[&str]) -> Config {
1919
config.out = dir;
2020
config.build = INTERNER.intern_str("A");
2121
config.hosts = vec![config.build]
22-
.clone()
2322
.into_iter()
2423
.chain(host.iter().map(|s| INTERNER.intern_str(s)))
2524
.collect::<Vec<_>>();

src/bootstrap/compile.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::str;
1818
use build_helper::{output, t, up_to_date};
1919
use filetime::FileTime;
2020
use serde::Deserialize;
21-
use serde_json;
2221

2322
use crate::builder::Cargo;
2423
use crate::dist;
@@ -149,7 +148,8 @@ fn copy_third_party_objects(
149148
// which is provided by std for this target.
150149
if target == "x86_64-fortanix-unknown-sgx" {
151150
let src_path_env = "X86_FORTANIX_SGX_LIBS";
152-
let src = env::var(src_path_env).expect(&format!("{} not found in env", src_path_env));
151+
let src =
152+
env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
153153
copy_and_stamp(Path::new(&src), "libunwind.a");
154154
}
155155

@@ -361,7 +361,7 @@ impl Step for StartupObjects {
361361
);
362362
}
363363

364-
let target = sysroot_dir.join(file.to_string() + ".o");
364+
let target = sysroot_dir.join((*file).to_string() + ".o");
365365
builder.copy(dst_file, &target);
366366
target_deps.push(target);
367367
}
@@ -515,7 +515,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interne
515515
.env("CFG_VERSION", builder.rust_version())
516516
.env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default());
517517

518-
let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib"));
518+
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
519519
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
520520

521521
if let Some(ref ver_date) = builder.rust_info.commit_date() {
@@ -843,11 +843,11 @@ pub fn run_cargo(
843843
};
844844
for filename in filenames {
845845
// Skip files like executables
846-
if !filename.ends_with(".rlib")
847-
&& !filename.ends_with(".lib")
848-
&& !filename.ends_with(".a")
849-
&& !is_dylib(&filename)
850-
&& !(is_check && filename.ends_with(".rmeta"))
846+
if !(filename.ends_with(".rlib")
847+
|| filename.ends_with(".lib")
848+
|| filename.ends_with(".a")
849+
|| is_dylib(&filename)
850+
|| (is_check && filename.ends_with(".rmeta")))
851851
{
852852
continue;
853853
}
@@ -905,7 +905,7 @@ pub fn run_cargo(
905905
for (prefix, extension, expected_len) in toplevel {
906906
let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
907907
filename.starts_with(&prefix[..])
908-
&& filename[prefix.len()..].starts_with("-")
908+
&& filename[prefix.len()..].starts_with('-')
909909
&& filename.ends_with(&extension[..])
910910
&& meta.len() == expected_len
911911
});

src/bootstrap/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::flags::Flags;
1616
pub use crate::flags::Subcommand;
1717
use build_helper::t;
1818
use serde::Deserialize;
19-
use toml;
2019

2120
/// Global configuration for the entire build and/or bootstrap.
2221
///
@@ -440,7 +439,7 @@ impl Config {
440439
}
441440
}
442441
})
443-
.unwrap_or_else(|| TomlConfig::default());
442+
.unwrap_or_else(TomlConfig::default);
444443

445444
let build = toml.build.clone().unwrap_or_default();
446445
// set by bootstrap.py
@@ -539,7 +538,7 @@ impl Config {
539538
config.llvm_ldflags = llvm.ldflags.clone();
540539
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
541540
config.llvm_use_linker = llvm.use_linker.clone();
542-
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.clone();
541+
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain;
543542
}
544543

545544
if let Some(ref rust) = toml.rust {
@@ -606,7 +605,7 @@ impl Config {
606605
target.ar = cfg.ar.clone().map(PathBuf::from);
607606
target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
608607
target.linker = cfg.linker.clone().map(PathBuf::from);
609-
target.crt_static = cfg.crt_static.clone();
608+
target.crt_static = cfg.crt_static;
610609
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
611610
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
612611
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);

src/bootstrap/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ impl Step for Analysis {
828828
assert!(builder.config.extended);
829829
let name = pkgname(builder, "rust-analysis");
830830

831-
if &compiler.host != builder.config.build {
831+
if compiler.host != builder.config.build {
832832
return distdir(builder).join(format!("{}-{}.tar.gz", name, target));
833833
}
834834

@@ -877,7 +877,7 @@ fn copy_src_dirs(builder: &Builder<'_>, src_dirs: &[&str], exclude_dirs: &[&str]
877877
Some(path) => path,
878878
None => return false,
879879
};
880-
if spath.ends_with("~") || spath.ends_with(".pyc") {
880+
if spath.ends_with('~') || spath.ends_with(".pyc") {
881881
return false;
882882
}
883883

src/bootstrap/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl Step for Rustdoc {
560560
builder.ensure(Rustc { stage, target });
561561

562562
// Build rustdoc.
563-
builder.ensure(tool::Rustdoc { compiler: compiler });
563+
builder.ensure(tool::Rustdoc { compiler });
564564

565565
// Symlink compiler docs to the output directory of rustdoc documentation.
566566
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");

src/bootstrap/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ fn split(s: &[String]) -> Vec<String> {
571571
}
572572

573573
fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> {
574-
match matches.opt_str("warnings").as_ref().map(|v| v.as_str()) {
574+
match matches.opt_str("warnings").as_deref() {
575575
Some("deny") => Some(true),
576576
Some("warn") => Some(false),
577577
Some(value) => {

src/bootstrap/install.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ fn add_destdir(path: &Path, destdir: &Option<PathBuf>) -> PathBuf {
126126
None => return path.to_path_buf(),
127127
};
128128
for part in path.components() {
129-
match part {
130-
Component::Normal(s) => ret.push(s),
131-
_ => {}
129+
if let Component::Normal(s) = part {
130+
ret.push(s)
132131
}
133132
}
134133
ret

src/bootstrap/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl Build {
444444
builder.execute_cli();
445445
} else {
446446
let builder = builder::Builder::new(&self);
447-
let _ = builder.execute_cli();
447+
builder.execute_cli();
448448
}
449449

450450
// Check for postponed failures from `test --no-fail-fast`.
@@ -839,7 +839,7 @@ impl Build {
839839
.target_config
840840
.get(&target)
841841
.and_then(|t| t.musl_root.as_ref())
842-
.or(self.config.musl_root.as_ref())
842+
.or_else(|| self.config.musl_root.as_ref())
843843
.map(|p| &**p)
844844
}
845845

src/bootstrap/metadata.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::process::Command;
55

66
use build_helper::output;
77
use serde::Deserialize;
8-
use serde_json;
98

109
use crate::cache::INTERNER;
1110
use crate::{Build, Crate};

src/bootstrap/native.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use std::path::{Path, PathBuf};
1515
use std::process::Command;
1616

1717
use build_helper::{output, t};
18-
use cc;
19-
use cmake;
2018

2119
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2220
use crate::cache::Interned;
@@ -205,7 +203,7 @@ impl Step for Llvm {
205203
cfg.define("LLVM_ENABLE_LIBXML2", "OFF");
206204
}
207205

208-
if enabled_llvm_projects.len() > 0 {
206+
if !enabled_llvm_projects.is_empty() {
209207
enabled_llvm_projects.sort();
210208
enabled_llvm_projects.dedup();
211209
cfg.define("LLVM_ENABLE_PROJECTS", enabled_llvm_projects.join(";"));

src/bootstrap/test.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,13 +1424,10 @@ impl Step for ErrorIndex {
14241424
}
14251425

14261426
fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1427-
match fs::read_to_string(markdown) {
1428-
Ok(contents) => {
1429-
if !contents.contains("```") {
1430-
return true;
1431-
}
1427+
if let Ok(contents) = fs::read_to_string(markdown) {
1428+
if !contents.contains("```") {
1429+
return true;
14321430
}
1433-
Err(_) => {}
14341431
}
14351432

14361433
builder.info(&format!("doc tests for: {}", markdown.display()));

src/bootstrap/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn prepare_tool_cargo(
234234
cargo.env("RUSTC_EXTERNAL_TOOL", "1");
235235
}
236236

237-
let mut features = extra_features.iter().cloned().collect::<Vec<_>>();
237+
let mut features = extra_features.to_vec();
238238
if builder.build.config.cargo_native_static {
239239
if path.ends_with("cargo")
240240
|| path.ends_with("rls")

src/bootstrap/toolstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
124124
let output = t!(String::from_utf8(output.stdout));
125125

126126
for (tool, submodule) in STABLE_TOOLS.iter().chain(NIGHTLY_TOOLS.iter()) {
127-
let changed = output.lines().any(|l| l.starts_with("M") && l.ends_with(submodule));
127+
let changed = output.lines().any(|l| l.starts_with('M') && l.ends_with(submodule));
128128
eprintln!("Verifying status of {}...", tool);
129129
if !changed {
130130
continue;

src/bootstrap/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Drop for TimeIt {
9898
fn drop(&mut self) {
9999
let time = self.1.elapsed();
100100
if !self.0 {
101-
println!("\tfinished in {}.{:03}", time.as_secs(), time.subsec_nanos() / 1_000_000);
101+
println!("\tfinished in {}.{:03}", time.as_secs(), time.subsec_millis());
102102
}
103103
}
104104
}

0 commit comments

Comments
 (0)