Skip to content

Commit

Permalink
bootstrap: apply most of clippy's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Feb 20, 2024
1 parent cce6a6e commit 8e8ca85
Show file tree
Hide file tree
Showing 30 changed files with 331 additions and 331 deletions.
10 changes: 5 additions & 5 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ fn main() {
.open(&lock_path)));
_build_lock_guard = match build_lock.try_write() {
Ok(mut lock) => {
t!(lock.write(&process::id().to_string().as_ref()));
t!(lock.write(process::id().to_string().as_ref()));
lock
}
err => {
drop(err);
println!("WARNING: build directory locked by process {pid}, waiting for lock");
let mut lock = t!(build_lock.write());
t!(lock.write(&process::id().to_string().as_ref()));
t!(lock.write(process::id().to_string().as_ref()));
lock
}
};
Expand Down Expand Up @@ -113,14 +113,14 @@ fn main() {
continue;
}

let file = t!(fs::File::open(&entry.path()));
let file = t!(fs::File::open(entry.path()));

// To ensure deterministic results we must sort the dump lines.
// This is necessary because the order of rustc invocations different
// almost all the time.
let mut lines: Vec<String> = t!(BufReader::new(&file).lines().collect());
lines.sort_by_key(|t| t.to_lowercase());
let mut file = t!(OpenOptions::new().write(true).truncate(true).open(&entry.path()));
let mut file = t!(OpenOptions::new().write(true).truncate(true).open(entry.path()));
t!(file.write_all(lines.join("\n").as_bytes()));
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ fn check_version(config: &Config) -> Option<String> {
msg.push_str("There have been changes to x.py since you last updated:\n");

for change in changes {
msg.push_str(&format!(" [{}] {}\n", change.severity.to_string(), change.summary));
msg.push_str(&format!(" [{}] {}\n", change.severity, change.summary));
msg.push_str(&format!(
" - PR Link https://github.com/rust-lang/rust/pull/{}\n",
change.change_id
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn main() {
dur.as_secs(),
dur.subsec_millis(),
if rusage_data.is_some() { " " } else { "" },
rusage_data.unwrap_or(String::new()),
rusage_data.unwrap_or_default(),
);
}
}
Expand Down Expand Up @@ -440,5 +440,5 @@ fn format_rusage_data(_child: Child) -> Option<String> {
));
}

return Some(init_str);
Some(init_str)
}
4 changes: 2 additions & 2 deletions src/bootstrap/src/bin/sccache-plus-cl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ fn main() {

// Invoke sccache with said compiler
let sccache_path = env::var_os("SCCACHE_PATH").unwrap();
let mut cmd = Command::new(&sccache_path);
let mut cmd = Command::new(sccache_path);
cmd.arg(compiler.path());
for &(ref k, ref v) in compiler.env() {
for (k, v) in compiler.env() {
cmd.env(k, v);
}
for arg in env::args().skip(1) {
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
&builder.config.cmd
{
// disable the most spammy clippy lints
let ignored_lints = vec![
let ignored_lints = [
"many_single_char_names", // there are a lot in stdarch
"collapsible_if",
"type_complexity",
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Step for Std {
if compiler.stage == 0 {
let libdir = builder.sysroot_libdir(compiler, target);
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
}
drop(_guard);

Expand Down Expand Up @@ -301,7 +301,7 @@ impl Step for Rustc {

let libdir = builder.sysroot_libdir(compiler, target);
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
add_to_sysroot(builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
}
}

Expand Down Expand Up @@ -353,7 +353,7 @@ impl Step for CodegenBackend {
.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);
let _guard = builder.msg_check(backend, target);

run_cargo(
builder,
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ fn rm_rf(path: &Path) {
Ok(metadata) => {
if metadata.file_type().is_file() || metadata.file_type().is_symlink() {
do_op(path, "remove file", |p| {
#[allow(clippy::bind_instead_of_map)]
fs::remove_file(p).or_else(|e| {
// Work around the fact that we cannot
// delete an executable while it runs on Windows.
Expand All @@ -204,6 +205,7 @@ fn rm_rf(path: &Path) {
rm_rf(&t!(file).path());
}
do_op(path, "remove dir", |p| {
#[allow(clippy::bind_instead_of_map)]
fs::remove_dir(p).or_else(|e| {
// Check for dir not empty on Windows
// FIXME: Once `ErrorKind::DirectoryNotEmpty` is stabilized,
Expand Down
58 changes: 29 additions & 29 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl Std {
) -> Vec<(PathBuf, DependencyType)> {
let mut deps = Vec::new();
if !self.is_for_mir_opt_tests {
deps.extend(copy_third_party_objects(builder, &compiler, target));
deps.extend(copy_self_contained_objects(builder, &compiler, target));
deps.extend(copy_third_party_objects(builder, compiler, target));
deps.extend(copy_self_contained_objects(builder, compiler, target));
}
deps
}
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Step for Std {

// Profiler information requires LLVM's compiler-rt
if builder.config.profiler {
builder.update_submodule(&Path::new("src/llvm-project"));
builder.update_submodule(Path::new("src/llvm-project"));
}

let mut target_deps = builder.ensure(StartupObjects { compiler, target });
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Step for Std {
if target.is_synthetic() {
cargo.env("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET", "1");
}
for rustflag in self.extra_rust_args.into_iter() {
for rustflag in self.extra_rust_args.iter() {
cargo.rustflag(rustflag);
}

Expand Down Expand Up @@ -333,7 +333,7 @@ fn copy_third_party_objects(
// The sanitizers are only copied in stage1 or above,
// to avoid creating dependency on LLVM.
target_deps.extend(
copy_sanitizers(builder, &compiler, target)
copy_sanitizers(builder, compiler, target)
.into_iter()
.map(|d| (d, DependencyType::Target)),
);
Expand Down Expand Up @@ -487,7 +487,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car

// for no-std targets we only compile a few no_std crates
cargo
.args(&["-p", "alloc"])
.args(["-p", "alloc"])
.arg("--manifest-path")
.arg(builder.src.join("library/alloc/Cargo.toml"))
.arg("--features")
Expand Down Expand Up @@ -626,20 +626,20 @@ impl Step for StdLink {
.build
.config
.initial_rustc
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"))
.starts_with(builder.out.join(compiler.host.triple).join("stage0/bin"))
{
// Copy bin files from stage0/bin to stage0-sysroot/bin
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
let sysroot = builder.out.join(compiler.host.triple).join("stage0-sysroot");

let host = compiler.host.triple;
let stage0_bin_dir = builder.out.join(&host).join("stage0/bin");
let stage0_bin_dir = builder.out.join(host).join("stage0/bin");
let sysroot_bin_dir = sysroot.join("bin");
t!(fs::create_dir_all(&sysroot_bin_dir));
builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir);

// Copy all *.so files from stage0/lib to stage0-sysroot/lib
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
let stage0_lib_dir = builder.out.join(host).join("stage0/lib");
if let Ok(files) = fs::read_dir(stage0_lib_dir) {
for file in files {
let file = t!(file);
let path = file.path();
Expand All @@ -654,9 +654,9 @@ impl Step for StdLink {
t!(fs::create_dir_all(&sysroot_codegen_backends));
let stage0_codegen_backends = builder
.out
.join(&host)
.join(host)
.join("stage0/lib/rustlib")
.join(&host)
.join(host)
.join("codegen-backends");
if stage0_codegen_backends.exists() {
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
Expand Down Expand Up @@ -1179,7 +1179,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
// The config can also specify its own llvm linker flags.
if let Some(ref s) = builder.config.llvm_ldflags {
if !llvm_linker_flags.is_empty() {
llvm_linker_flags.push_str(" ");
llvm_linker_flags.push(' ');
}
llvm_linker_flags.push_str(s);
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
for path_set in &run.paths {
needs_codegen_cfg = match path_set {
PathSet::Set(set) => set.iter().any(|p| is_codegen_cfg_needed(p, run)),
PathSet::Suite(suite) => is_codegen_cfg_needed(&suite, run),
PathSet::Suite(suite) => is_codegen_cfg_needed(suite, run),
}
}
needs_codegen_cfg
Expand All @@ -1279,7 +1279,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";

fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
if path.path.to_str().unwrap().contains(&CODEGEN_BACKEND_PREFIX) {
if path.path.to_str().unwrap().contains(CODEGEN_BACKEND_PREFIX) {
let mut needs_codegen_backend_config = true;
for &backend in run.builder.config.codegen_backends(run.target) {
if path
Expand All @@ -1300,7 +1300,7 @@ fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
}
}

return false;
false
}

impl Step for CodegenBackend {
Expand Down Expand Up @@ -1393,7 +1393,7 @@ impl Step for CodegenBackend {
}
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
let codegen_backend = codegen_backend.to_str().unwrap();
t!(fs::write(&stamp, &codegen_backend));
t!(fs::write(stamp, codegen_backend));
}
}

Expand Down Expand Up @@ -1441,7 +1441,7 @@ fn copy_codegen_backends_to_sysroot(
let dot = filename.find('.').unwrap();
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
};
builder.copy(&file, &dst.join(target_filename));
builder.copy(file, &dst.join(target_filename));
}
}

Expand Down Expand Up @@ -1519,7 +1519,7 @@ impl Step for Sysroot {
/// 1-3.
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
let compiler = self.compiler;
let host_dir = builder.out.join(&compiler.host.triple);
let host_dir = builder.out.join(compiler.host.triple);

let sysroot_dir = |stage| {
if stage == 0 {
Expand Down Expand Up @@ -1578,7 +1578,7 @@ impl Step for Sysroot {
let mut add_filtered_files = |suffix, contents| {
for path in contents {
let path = Path::new(&path);
if path.parent().map_or(false, |parent| parent.ends_with(&suffix)) {
if path.parent().map_or(false, |parent| parent.ends_with(suffix)) {
filtered_files.push(path.file_name().unwrap().to_owned());
}
}
Expand Down Expand Up @@ -1802,7 +1802,7 @@ impl Step for Assemble {
if let Some(lld_install) = lld_install {
let src_exe = exe("lld", target_compiler.host);
let dst_exe = exe("rust-lld", target_compiler.host);
builder.copy(&lld_install.join("bin").join(&src_exe), &libdir_bin.join(&dst_exe));
builder.copy(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
t!(fs::create_dir_all(&self_contained_lld_dir));
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
Expand Down Expand Up @@ -1850,7 +1850,7 @@ impl Step for Assemble {
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
let rustc = out_dir.join(exe("rustc-main", host));
let bindir = sysroot.join("bin");
t!(fs::create_dir_all(&bindir));
t!(fs::create_dir_all(bindir));
let compiler = builder.rustc(target_compiler);
builder.copy(&rustc, &compiler);

Expand All @@ -1869,9 +1869,9 @@ pub fn add_to_sysroot(
stamp: &Path,
) {
let self_contained_dst = &sysroot_dst.join("self-contained");
t!(fs::create_dir_all(&sysroot_dst));
t!(fs::create_dir_all(&sysroot_host_dst));
t!(fs::create_dir_all(&self_contained_dst));
t!(fs::create_dir_all(sysroot_dst));
t!(fs::create_dir_all(sysroot_host_dst));
t!(fs::create_dir_all(self_contained_dst));
for (path, dependency_type) in builder.read_stamp_file(stamp) {
let dst = match dependency_type {
DependencyType::Host => sysroot_host_dst,
Expand Down Expand Up @@ -2009,14 +2009,14 @@ pub fn run_cargo(
.map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata())))
.collect::<Vec<_>>();
for (prefix, extension, expected_len) in toplevel {
let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
let candidates = contents.iter().filter(|&(_, filename, meta)| {
meta.len() == expected_len
&& filename
.strip_prefix(&prefix[..])
.map(|s| s.starts_with('-') && s.ends_with(&extension[..]))
.unwrap_or(false)
});
let max = candidates.max_by_key(|&&(_, _, ref metadata)| {
let max = candidates.max_by_key(|&(_, _, metadata)| {
metadata.modified().expect("mtime should be available on all relevant OSes")
});
let path_to_add = match max {
Expand Down Expand Up @@ -2045,7 +2045,7 @@ pub fn run_cargo(
new_contents.extend(dep.to_str().unwrap().as_bytes());
new_contents.extend(b"\0");
}
t!(fs::write(&stamp, &new_contents));
t!(fs::write(stamp, &new_contents));
deps.into_iter().map(|(d, _)| d).collect()
}

Expand Down
Loading

0 comments on commit 8e8ca85

Please sign in to comment.