Skip to content

Commit 67c116f

Browse files
committed
fix clippy warnings on bootstrap
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 214bf5a commit 67c116f

22 files changed

+187
-165
lines changed

Diff for: src/bootstrap/src/bin/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn check_version(config: &Config) -> Option<String> {
144144
// more than once.
145145
if let Ok(t) = fs::read_to_string(&warned_id_path) {
146146
let last_warned_id =
147-
usize::from_str(&t).expect(&format!("{} is corrupted.", warned_id_path.display()));
147+
usize::from_str(&t).unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));
148148

149149
// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
150150
// Otherwise, we may retrieve all the changes if it's not the highest value.

Diff for: src/bootstrap/src/core/build_steps/clean.rs

+19-25
Original file line numberDiff line numberDiff line change
@@ -181,39 +181,33 @@ fn rm_rf(path: &Path) {
181181
}
182182
Ok(metadata) => {
183183
if metadata.file_type().is_file() || metadata.file_type().is_symlink() {
184-
do_op(path, "remove file", |p| {
185-
fs::remove_file(p).or_else(|e| {
186-
// Work around the fact that we cannot
187-
// delete an executable while it runs on Windows.
188-
#[cfg(windows)]
184+
do_op(path, "remove file", |p| match fs::remove_file(p) {
185+
#[cfg(windows)]
186+
Err(e)
189187
if e.kind() == std::io::ErrorKind::PermissionDenied
190188
&& p.file_name().and_then(std::ffi::OsStr::to_str)
191-
== Some("bootstrap.exe")
192-
{
193-
eprintln!("WARNING: failed to delete '{}'.", p.display());
194-
return Ok(());
195-
}
196-
Err(e)
197-
})
189+
== Some("bootstrap.exe") =>
190+
{
191+
eprintln!("WARNING: failed to delete '{}'.", p.display());
192+
Ok(())
193+
}
194+
r => r,
198195
});
196+
199197
return;
200198
}
201199

202200
for file in t!(fs::read_dir(path)) {
203201
rm_rf(&t!(file).path());
204202
}
205-
do_op(path, "remove dir", |p| {
206-
fs::remove_dir(p).or_else(|e| {
207-
// Check for dir not empty on Windows
208-
// FIXME: Once `ErrorKind::DirectoryNotEmpty` is stabilized,
209-
// match on `e.kind()` instead.
210-
#[cfg(windows)]
211-
if e.raw_os_error() == Some(145) {
212-
return Ok(());
213-
}
214203

215-
Err(e)
216-
})
204+
do_op(path, "remove dir", |p| match fs::remove_dir(p) {
205+
// Check for dir not empty on Windows
206+
// FIXME: Once `ErrorKind::DirectoryNotEmpty` is stabilized,
207+
// match on `e.kind()` instead.
208+
#[cfg(windows)]
209+
Err(e) if e.raw_os_error() == Some(145) => Ok(()),
210+
r => r,
217211
});
218212
}
219213
};
@@ -228,14 +222,14 @@ where
228222
// On windows we can't remove a readonly file, and git will often clone files as readonly.
229223
// As a result, we have some special logic to remove readonly files on windows.
230224
// This is also the reason that we can't use things like fs::remove_dir_all().
231-
Err(ref e) if cfg!(windows) && e.kind() == ErrorKind::PermissionDenied => {
225+
#[cfg(windows)]
226+
Err(ref e) if e.kind() == ErrorKind::PermissionDenied => {
232227
let m = t!(path.symlink_metadata());
233228
let mut p = m.permissions();
234229
p.set_readonly(false);
235230
t!(fs::set_permissions(path, p));
236231
f(path).unwrap_or_else(|e| {
237232
// Delete symlinked directories on Windows
238-
#[cfg(windows)]
239233
if m.file_type().is_symlink() && path.is_dir() && fs::remove_dir(path).is_ok() {
240234
return;
241235
}

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ pub fn rustc_cargo_env(
11461146
// busting caches (e.g. like #71152).
11471147
if builder.config.llvm_enabled(target) {
11481148
let building_is_expensive =
1149-
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target).is_err();
1149+
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target).should_build();
11501150
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
11511151
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == stage;
11521152
let should_skip_build = building_is_expensive && can_skip_build;
@@ -1293,7 +1293,7 @@ fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
12931293
.path
12941294
.to_str()
12951295
.unwrap()
1296-
.ends_with(&(CODEGEN_BACKEND_PREFIX.to_owned() + &backend))
1296+
.ends_with(&(CODEGEN_BACKEND_PREFIX.to_owned() + backend))
12971297
{
12981298
needs_codegen_backend_config = false;
12991299
}
@@ -1853,7 +1853,7 @@ impl Step for Assemble {
18531853
extra_features: vec![],
18541854
});
18551855
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
1856-
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
1856+
builder.copy_link(&src_path, &libdir_bin.join(tool_exe));
18571857
}
18581858

18591859
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,

Diff for: src/bootstrap/src/core/build_steps/dist.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Step for JsonDocs {
107107
builder.top_stage,
108108
host,
109109
builder,
110-
DocumentationFormat::JSON,
110+
DocumentationFormat::Json,
111111
));
112112

113113
let dest = "share/doc/rust/json";
@@ -1131,7 +1131,7 @@ impl Step for Rls {
11311131
let rls = builder.ensure(tool::Rls { compiler, target, extra_features: Vec::new() });
11321132

11331133
let mut tarball = Tarball::new(builder, "rls", &target.triple);
1134-
tarball.set_overlay(OverlayKind::RLS);
1134+
tarball.set_overlay(OverlayKind::Rls);
11351135
tarball.is_preview(true);
11361136
tarball.add_file(rls, "bin", 0o755);
11371137
tarball.add_legal_and_readme_to("share/doc/rls");
@@ -2059,7 +2059,7 @@ fn install_llvm_file(
20592059
if install_symlink {
20602060
// For download-ci-llvm, also install the symlink, to match what LLVM does. Using a
20612061
// symlink is fine here, as this is not a rustup component.
2062-
builder.copy_link(&source, &full_dest);
2062+
builder.copy_link(source, &full_dest);
20632063
} else {
20642064
// Otherwise, replace the symlink with an equivalent linker script. This is used when
20652065
// projects like miri link against librustc_driver.so. We don't use a symlink, as
@@ -2076,7 +2076,7 @@ fn install_llvm_file(
20762076
}
20772077
}
20782078
} else {
2079-
builder.install(&source, destination, 0o644);
2079+
builder.install(source, destination, 0o644);
20802080
}
20812081
}
20822082

@@ -2121,7 +2121,7 @@ fn maybe_install_llvm(
21212121
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
21222122
}
21232123
!builder.config.dry_run()
2124-
} else if let Ok(llvm::LlvmResult { llvm_config, .. }) =
2124+
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
21252125
llvm::prebuilt_llvm_config(builder, target)
21262126
{
21272127
let mut cmd = Command::new(llvm_config);
@@ -2202,7 +2202,7 @@ impl Step for LlvmTools {
22022202
builder.ensure(crate::core::build_steps::llvm::Llvm { target });
22032203

22042204
let mut tarball = Tarball::new(builder, "llvm-tools", &target.triple);
2205-
tarball.set_overlay(OverlayKind::LLVM);
2205+
tarball.set_overlay(OverlayKind::Llvm);
22062206
tarball.is_preview(true);
22072207

22082208
if builder.config.llvm_tools_enabled {
@@ -2305,7 +2305,7 @@ impl Step for RustDev {
23052305
}
23062306

23072307
let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);
2308-
tarball.set_overlay(OverlayKind::LLVM);
2308+
tarball.set_overlay(OverlayKind::Llvm);
23092309
// LLVM requires a shared object symlink to exist on some platforms.
23102310
tarball.permit_symlinks(true);
23112311

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ impl Step for Std {
567567
stage: run.builder.top_stage,
568568
target: run.target,
569569
format: if run.builder.config.cmd.json() {
570-
DocumentationFormat::JSON
570+
DocumentationFormat::Json
571571
} else {
572-
DocumentationFormat::HTML
572+
DocumentationFormat::Html
573573
},
574574
crates: run.make_run_crates(Alias::Library),
575575
});
@@ -583,13 +583,13 @@ impl Step for Std {
583583
let stage = self.stage;
584584
let target = self.target;
585585
let out = match self.format {
586-
DocumentationFormat::HTML => builder.doc_out(target),
587-
DocumentationFormat::JSON => builder.json_doc_out(target),
586+
DocumentationFormat::Html => builder.doc_out(target),
587+
DocumentationFormat::Json => builder.json_doc_out(target),
588588
};
589589

590590
t!(fs::create_dir_all(&out));
591591

592-
if self.format == DocumentationFormat::HTML {
592+
if self.format == DocumentationFormat::Html {
593593
builder.ensure(SharedAssets { target: self.target });
594594
}
595595

@@ -600,10 +600,10 @@ impl Step for Std {
600600
.into_string()
601601
.expect("non-utf8 paths are unsupported");
602602
let mut extra_args = match self.format {
603-
DocumentationFormat::HTML => {
603+
DocumentationFormat::Html => {
604604
vec!["--markdown-css", "rust.css", "--markdown-no-toc", "--index-page", &index_page]
605605
}
606-
DocumentationFormat::JSON => vec!["--output-format", "json"],
606+
DocumentationFormat::Json => vec!["--output-format", "json"],
607607
};
608608

609609
if !builder.config.docs_minification {
@@ -613,7 +613,7 @@ impl Step for Std {
613613
doc_std(builder, self.format, stage, target, &out, &extra_args, &self.crates);
614614

615615
// Don't open if the format is json
616-
if let DocumentationFormat::JSON = self.format {
616+
if let DocumentationFormat::Json = self.format {
617617
return;
618618
}
619619

@@ -646,15 +646,15 @@ const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "tes
646646

647647
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
648648
pub enum DocumentationFormat {
649-
HTML,
650-
JSON,
649+
Html,
650+
Json,
651651
}
652652

653653
impl DocumentationFormat {
654654
fn as_str(&self) -> &str {
655655
match self {
656-
DocumentationFormat::HTML => "HTML",
657-
DocumentationFormat::JSON => "JSON",
656+
DocumentationFormat::Html => "HTML",
657+
DocumentationFormat::Json => "JSON",
658658
}
659659
}
660660
}
@@ -678,7 +678,7 @@ fn doc_std(
678678

679679
let compiler = builder.compiler(stage, builder.config.build);
680680

681-
let target_doc_dir_name = if format == DocumentationFormat::JSON { "json-doc" } else { "doc" };
681+
let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" };
682682
let target_dir =
683683
builder.stage_out(compiler, Mode::Std).join(target.triple).join(target_doc_dir_name);
684684

Diff for: src/bootstrap/src/core/build_steps/format.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,10 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
225225
Some(first) => {
226226
let find_shortcut_candidates = |p: &PathBuf| {
227227
let mut candidates = Vec::new();
228-
for candidate in WalkBuilder::new(src.clone()).max_depth(Some(3)).build() {
229-
if let Ok(entry) = candidate {
230-
if let Some(dir_name) = p.file_name() {
231-
if entry.path().is_dir() && entry.file_name() == dir_name {
232-
candidates.push(entry.into_path());
233-
}
228+
for entry in WalkBuilder::new(src.clone()).max_depth(Some(3)).build().map_while(Result::ok) {
229+
if let Some(dir_name) = p.file_name() {
230+
if entry.path().is_dir() && entry.file_name() == dir_name {
231+
candidates.push(entry.into_path());
234232
}
235233
}
236234
}

Diff for: src/bootstrap/src/core/build_steps/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf) -> String {
130130
// https://www.gnu.org/prep/standards/html_node/DESTDIR.html
131131
if let Some(destdir) = destdir_env {
132132
let without_destdir = path.clone();
133-
path = destdir.clone();
133+
path.clone_from(destdir);
134134
// Custom .join() which ignores disk roots.
135135
for part in without_destdir.components() {
136136
if let Component::Normal(s) = part {

Diff for: src/bootstrap/src/core/build_steps/llvm.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ pub struct Meta {
4242
root: String,
4343
}
4444

45+
pub enum LlvmBuildStatus {
46+
AlreadyBuilt(LlvmResult),
47+
ShouldBuild(Meta),
48+
}
49+
50+
impl LlvmBuildStatus {
51+
pub fn should_build(&self) -> bool {
52+
match self {
53+
LlvmBuildStatus::AlreadyBuilt(_) => false,
54+
LlvmBuildStatus::ShouldBuild(_) => true
55+
}
56+
}
57+
}
58+
4559
// Linker flags to pass to LLVM's CMake invocation.
4660
#[derive(Debug, Clone, Default)]
4761
struct LdFlags {
@@ -75,7 +89,7 @@ impl LdFlags {
7589
pub fn prebuilt_llvm_config(
7690
builder: &Builder<'_>,
7791
target: TargetSelection,
78-
) -> Result<LlvmResult, Meta> {
92+
) -> LlvmBuildStatus {
7993
// If we have llvm submodule initialized already, sync it.
8094
builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
8195

@@ -93,7 +107,7 @@ pub fn prebuilt_llvm_config(
93107
llvm_cmake_dir.push("lib");
94108
llvm_cmake_dir.push("cmake");
95109
llvm_cmake_dir.push("llvm");
96-
return Ok(LlvmResult { llvm_config, llvm_cmake_dir });
110+
return LlvmBuildStatus::AlreadyBuilt(LlvmResult { llvm_config, llvm_cmake_dir });
97111
}
98112
}
99113

@@ -131,10 +145,10 @@ pub fn prebuilt_llvm_config(
131145
stamp.path.display()
132146
));
133147
}
134-
return Ok(res);
148+
return LlvmBuildStatus::AlreadyBuilt(res);
135149
}
136150

137-
Err(Meta { stamp, res, out_dir, root: root.into() })
151+
LlvmBuildStatus::ShouldBuild(Meta { stamp, res, out_dir, root: root.into() })
138152
}
139153

140154
/// This retrieves the LLVM sha we *want* to use, according to git history.
@@ -282,8 +296,8 @@ impl Step for Llvm {
282296

283297
// If LLVM has already been built or been downloaded through download-ci-llvm, we avoid building it again.
284298
let Meta { stamp, res, out_dir, root } = match prebuilt_llvm_config(builder, target) {
285-
Ok(p) => return p,
286-
Err(m) => m,
299+
LlvmBuildStatus::AlreadyBuilt(p) => return p,
300+
LlvmBuildStatus::ShouldBuild(m) => m,
287301
};
288302

289303
if builder.llvm_link_shared() && target.is_windows() {

Diff for: src/bootstrap/src/core/build_steps/setup.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl FromStr for Profile {
9393
Ok(Profile::Tools)
9494
}
9595
"none" => Ok(Profile::None),
96-
"llvm" | "codegen" => Err(format!(
96+
"llvm" | "codegen" => Err(
9797
"the \"llvm\" and \"codegen\" profiles have been removed,\
98-
use \"compiler\" instead which has the same functionality"
99-
)),
98+
use \"compiler\" instead which has the same functionality".to_string()
99+
),
100100
_ => Err(format!("unknown profile: '{s}'")),
101101
}
102102
}
@@ -474,10 +474,10 @@ impl Step for Hook {
474474

475475
// install a git hook to automatically run tidy, if they want
476476
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
477-
let git = t!(config.git().args(["rev-parse", "--git-common-dir"]).output().map(|output| {
477+
let git = config.git().args(["rev-parse", "--git-common-dir"]).output().map(|output| {
478478
assert!(output.status.success(), "failed to run `git`");
479479
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
480-
}));
480+
})?;
481481
let hooks_dir = git.join("hooks");
482482
let dst = hooks_dir.join("pre-push");
483483
if dst.exists() {

Diff for: src/bootstrap/src/core/build_steps/test.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ impl Step for RustdocJSStd {
923923
builder.top_stage,
924924
self.target,
925925
builder,
926-
DocumentationFormat::HTML,
926+
DocumentationFormat::Html,
927927
));
928928
let _guard = builder.msg(
929929
Kind::Test,
@@ -1389,10 +1389,10 @@ impl Step for RunMakeSupport {
13891389
builder.run(&mut cargo);
13901390

13911391
let lib_name = "librun_make_support.rlib";
1392-
let lib = builder.tools_dir(self.compiler).join(&lib_name);
1392+
let lib = builder.tools_dir(self.compiler).join(lib_name);
13931393

13941394
let cargo_out =
1395-
builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(&lib_name);
1395+
builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(lib_name);
13961396
builder.copy_link(&cargo_out, &lib);
13971397
lib
13981398
}
@@ -2483,6 +2483,7 @@ impl Step for CrateLibrustc {
24832483
/// Given a `cargo test` subcommand, add the appropriate flags and run it.
24842484
///
24852485
/// Returns whether the test succeeded.
2486+
#[allow(clippy::too_many_arguments)] // FIXME: reduce the number of args and remove this.
24862487
fn run_cargo_test<'a>(
24872488
cargo: impl Into<Command>,
24882489
libtest_args: &[&str],

0 commit comments

Comments
 (0)