Skip to content

Commit ae3f4f1

Browse files
committed
bootstrap: apply most of clippy's suggestions
1 parent bb59453 commit ae3f4f1

29 files changed

+317
-326
lines changed

src/bootstrap/src/bin/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ fn main() {
3939
.open(&lock_path)));
4040
_build_lock_guard = match build_lock.try_write() {
4141
Ok(mut lock) => {
42-
t!(lock.write(&process::id().to_string().as_ref()));
42+
t!(lock.write(process::id().to_string().as_ref()));
4343
lock
4444
}
4545
err => {
4646
drop(err);
4747
println!("WARNING: build directory locked by process {pid}, waiting for lock");
4848
let mut lock = t!(build_lock.write());
49-
t!(lock.write(&process::id().to_string().as_ref()));
49+
t!(lock.write(process::id().to_string().as_ref()));
5050
lock
5151
}
5252
};
@@ -113,14 +113,14 @@ fn main() {
113113
continue;
114114
}
115115

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

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

158158
for change in changes {
159-
msg.push_str(&format!(" [{}] {}\n", change.severity.to_string(), change.summary));
159+
msg.push_str(&format!(" [{}] {}\n", change.severity, change.summary));
160160
msg.push_str(&format!(
161161
" - PR Link https://github.com/rust-lang/rust/pull/{}\n",
162162
change.change_id

src/bootstrap/src/bin/rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn main() {
276276
dur.as_secs(),
277277
dur.subsec_millis(),
278278
if rusage_data.is_some() { " " } else { "" },
279-
rusage_data.unwrap_or(String::new()),
279+
rusage_data.unwrap_or_default(),
280280
);
281281
}
282282
}
@@ -440,5 +440,5 @@ fn format_rusage_data(_child: Child) -> Option<String> {
440440
));
441441
}
442442

443-
return Some(init_str);
443+
Some(init_str)
444444
}

src/bootstrap/src/bin/sccache-plus-cl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ fn main() {
1818

1919
// Invoke sccache with said compiler
2020
let sccache_path = env::var_os("SCCACHE_PATH").unwrap();
21-
let mut cmd = Command::new(&sccache_path);
21+
let mut cmd = Command::new(sccache_path);
2222
cmd.arg(compiler.path());
23-
for &(ref k, ref v) in compiler.env() {
23+
for (k, v) in compiler.env() {
2424
cmd.env(k, v);
2525
}
2626
for arg in env::args().skip(1) {

src/bootstrap/src/core/build_steps/check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
3434
&builder.config.cmd
3535
{
3636
// disable the most spammy clippy lints
37-
let ignored_lints = vec![
37+
let ignored_lints = [
3838
"many_single_char_names", // there are a lot in stdarch
3939
"collapsible_if",
4040
"type_complexity",
@@ -150,7 +150,7 @@ impl Step for Std {
150150
if compiler.stage == 0 {
151151
let libdir = builder.sysroot_libdir(compiler, target);
152152
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
153-
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
153+
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
154154
}
155155
drop(_guard);
156156

@@ -301,7 +301,7 @@ impl Step for Rustc {
301301

302302
let libdir = builder.sysroot_libdir(compiler, target);
303303
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
304-
add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
304+
add_to_sysroot(builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
305305
}
306306
}
307307

@@ -353,7 +353,7 @@ impl Step for CodegenBackend {
353353
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
354354
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
355355

356-
let _guard = builder.msg_check(&backend, target);
356+
let _guard = builder.msg_check(backend, target);
357357

358358
run_cargo(
359359
builder,

src/bootstrap/src/core/build_steps/compile.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl Std {
107107
) -> Vec<(PathBuf, DependencyType)> {
108108
let mut deps = Vec::new();
109109
if !self.is_for_mir_opt_tests {
110-
deps.extend(copy_third_party_objects(builder, &compiler, target));
111-
deps.extend(copy_self_contained_objects(builder, &compiler, target));
110+
deps.extend(copy_third_party_objects(builder, compiler, target));
111+
deps.extend(copy_self_contained_objects(builder, compiler, target));
112112
}
113113
deps
114114
}
@@ -186,7 +186,7 @@ impl Step for Std {
186186

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

192192
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
@@ -271,7 +271,7 @@ impl Step for Std {
271271
if target.is_synthetic() {
272272
cargo.env("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET", "1");
273273
}
274-
for rustflag in self.extra_rust_args.into_iter() {
274+
for rustflag in self.extra_rust_args.iter() {
275275
cargo.rustflag(rustflag);
276276
}
277277

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

488488
// for no-std targets we only compile a few no_std crates
489489
cargo
490-
.args(&["-p", "alloc"])
490+
.args(["-p", "alloc"])
491491
.arg("--manifest-path")
492492
.arg(builder.src.join("library/alloc/Cargo.toml"))
493493
.arg("--features")
@@ -626,20 +626,20 @@ impl Step for StdLink {
626626
.build
627627
.config
628628
.initial_rustc
629-
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"))
629+
.starts_with(builder.out.join(compiler.host.triple).join("stage0/bin"))
630630
{
631631
// Copy bin files from stage0/bin to stage0-sysroot/bin
632-
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
632+
let sysroot = builder.out.join(compiler.host.triple).join("stage0-sysroot");
633633

634634
let host = compiler.host.triple;
635-
let stage0_bin_dir = builder.out.join(&host).join("stage0/bin");
635+
let stage0_bin_dir = builder.out.join(host).join("stage0/bin");
636636
let sysroot_bin_dir = sysroot.join("bin");
637637
t!(fs::create_dir_all(&sysroot_bin_dir));
638638
builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir);
639639

640640
// Copy all *.so files from stage0/lib to stage0-sysroot/lib
641-
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
642-
if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
641+
let stage0_lib_dir = builder.out.join(host).join("stage0/lib");
642+
if let Ok(files) = fs::read_dir(stage0_lib_dir) {
643643
for file in files {
644644
let file = t!(file);
645645
let path = file.path();
@@ -654,9 +654,9 @@ impl Step for StdLink {
654654
t!(fs::create_dir_all(&sysroot_codegen_backends));
655655
let stage0_codegen_backends = builder
656656
.out
657-
.join(&host)
657+
.join(host)
658658
.join("stage0/lib/rustlib")
659-
.join(&host)
659+
.join(host)
660660
.join("codegen-backends");
661661
if stage0_codegen_backends.exists() {
662662
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
@@ -1179,7 +1179,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
11791179
// The config can also specify its own llvm linker flags.
11801180
if let Some(ref s) = builder.config.llvm_ldflags {
11811181
if !llvm_linker_flags.is_empty() {
1182-
llvm_linker_flags.push_str(" ");
1182+
llvm_linker_flags.push(' ');
11831183
}
11841184
llvm_linker_flags.push_str(s);
11851185
}
@@ -1270,7 +1270,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
12701270
for path_set in &run.paths {
12711271
needs_codegen_cfg = match path_set {
12721272
PathSet::Set(set) => set.iter().any(|p| is_codegen_cfg_needed(p, run)),
1273-
PathSet::Suite(suite) => is_codegen_cfg_needed(&suite, run),
1273+
PathSet::Suite(suite) => is_codegen_cfg_needed(suite, run),
12741274
}
12751275
}
12761276
needs_codegen_cfg
@@ -1279,7 +1279,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
12791279
pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
12801280

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

1303-
return false;
1303+
false
13041304
}
13051305

13061306
impl Step for CodegenBackend {
@@ -1393,7 +1393,7 @@ impl Step for CodegenBackend {
13931393
}
13941394
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
13951395
let codegen_backend = codegen_backend.to_str().unwrap();
1396-
t!(fs::write(&stamp, &codegen_backend));
1396+
t!(fs::write(stamp, codegen_backend));
13971397
}
13981398
}
13991399

@@ -1441,7 +1441,7 @@ fn copy_codegen_backends_to_sysroot(
14411441
let dot = filename.find('.').unwrap();
14421442
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
14431443
};
1444-
builder.copy(&file, &dst.join(target_filename));
1444+
builder.copy(file, &dst.join(target_filename));
14451445
}
14461446
}
14471447

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

15241524
let sysroot_dir = |stage| {
15251525
if stage == 0 {
@@ -1578,7 +1578,7 @@ impl Step for Sysroot {
15781578
let mut add_filtered_files = |suffix, contents| {
15791579
for path in contents {
15801580
let path = Path::new(&path);
1581-
if path.parent().map_or(false, |parent| parent.ends_with(&suffix)) {
1581+
if path.parent().map_or(false, |parent| parent.ends_with(suffix)) {
15821582
filtered_files.push(path.file_name().unwrap().to_owned());
15831583
}
15841584
}
@@ -1802,7 +1802,7 @@ impl Step for Assemble {
18021802
if let Some(lld_install) = lld_install {
18031803
let src_exe = exe("lld", target_compiler.host);
18041804
let dst_exe = exe("rust-lld", target_compiler.host);
1805-
builder.copy(&lld_install.join("bin").join(&src_exe), &libdir_bin.join(&dst_exe));
1805+
builder.copy(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
18061806
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
18071807
t!(fs::create_dir_all(&self_contained_lld_dir));
18081808
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
@@ -1850,7 +1850,7 @@ impl Step for Assemble {
18501850
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
18511851
let rustc = out_dir.join(exe("rustc-main", host));
18521852
let bindir = sysroot.join("bin");
1853-
t!(fs::create_dir_all(&bindir));
1853+
t!(fs::create_dir_all(bindir));
18541854
let compiler = builder.rustc(target_compiler);
18551855
builder.copy(&rustc, &compiler);
18561856

@@ -1869,9 +1869,9 @@ pub fn add_to_sysroot(
18691869
stamp: &Path,
18701870
) {
18711871
let self_contained_dst = &sysroot_dst.join("self-contained");
1872-
t!(fs::create_dir_all(&sysroot_dst));
1873-
t!(fs::create_dir_all(&sysroot_host_dst));
1874-
t!(fs::create_dir_all(&self_contained_dst));
1872+
t!(fs::create_dir_all(sysroot_dst));
1873+
t!(fs::create_dir_all(sysroot_host_dst));
1874+
t!(fs::create_dir_all(self_contained_dst));
18751875
for (path, dependency_type) in builder.read_stamp_file(stamp) {
18761876
let dst = match dependency_type {
18771877
DependencyType::Host => sysroot_host_dst,
@@ -2009,14 +2009,14 @@ pub fn run_cargo(
20092009
.map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata())))
20102010
.collect::<Vec<_>>();
20112011
for (prefix, extension, expected_len) in toplevel {
2012-
let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
2012+
let candidates = contents.iter().filter(|&(_, filename, meta)| {
20132013
meta.len() == expected_len
20142014
&& filename
20152015
.strip_prefix(&prefix[..])
20162016
.map(|s| s.starts_with('-') && s.ends_with(&extension[..]))
20172017
.unwrap_or(false)
20182018
});
2019-
let max = candidates.max_by_key(|&&(_, _, ref metadata)| {
2019+
let max = candidates.max_by_key(|&(_, _, metadata)| {
20202020
metadata.modified().expect("mtime should be available on all relevant OSes")
20212021
});
20222022
let path_to_add = match max {
@@ -2045,7 +2045,7 @@ pub fn run_cargo(
20452045
new_contents.extend(dep.to_str().unwrap().as_bytes());
20462046
new_contents.extend(b"\0");
20472047
}
2048-
t!(fs::write(&stamp, &new_contents));
2048+
t!(fs::write(stamp, &new_contents));
20492049
deps.into_iter().map(|(d, _)| d).collect()
20502050
}
20512051

0 commit comments

Comments
 (0)