From b47d36d8d1c22aa036021cc7a3c91f9edce043dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 17 Jun 2025 09:47:37 +0200 Subject: [PATCH 1/2] Remove `override_build_kind` It doesn't seem to be needed, we can just use `Kind::Check` explicitly. --- src/bootstrap/src/core/build_steps/check.rs | 26 +++----------------- src/bootstrap/src/core/build_steps/clippy.rs | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f47873590a17b..f5dae626a89bd 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -199,13 +199,6 @@ pub struct Rustc { /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc crates: Vec, - /// Override `Builder::kind` on cargo invocations. - /// - /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations. - /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`, - /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library, - /// which is not useful if we only want to lint a few crates with specific rules. - override_build_kind: Option, } impl Rustc { @@ -215,12 +208,7 @@ impl Rustc { .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { target, crates, override_build_kind: None } - } - - pub fn build_kind(mut self, build_kind: Option) -> Self { - self.override_build_kind = build_kind; - self + Self { target, crates } } } @@ -235,7 +223,7 @@ impl Step for Rustc { fn make_run(run: RunConfig<'_>) { let crates = run.make_run_crates(Alias::Compiler); - run.builder.ensure(Rustc { target: run.target, crates, override_build_kind: None }); + run.builder.ensure(Rustc { target: run.target, crates }); } /// Builds the compiler. @@ -256,7 +244,7 @@ impl Step for Rustc { builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host)); builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target)); } else { - builder.ensure(Std::new(target).build_kind(self.override_build_kind)); + builder.ensure(Std::new(target)); } let mut cargo = builder::Cargo::new( @@ -265,17 +253,11 @@ impl Step for Rustc { Mode::Rustc, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } - // Explicitly pass -p for all compiler crates -- this will force cargo // to also check the tests/benches/examples for these crates, rather // than just the leaf crate. diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 788a3b9601d9d..f1932479d4679 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -289,7 +289,7 @@ macro_rules! lint_any { let target = self.target; if !builder.download_rustc() { - builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check))); + builder.ensure(check::Rustc::new(target, builder)); }; let cargo = prepare_tool_cargo( From 887566881f92051cf29be482fae0b8c9cced1af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 17 Jun 2025 13:09:43 +0200 Subject: [PATCH 2/2] Remove useless conditions about Clippy We should always just use `Kind::Check` for the check steps, as Clippy now has an entirely separate set of steps. --- src/bootstrap/src/core/build_steps/check.rs | 51 ++++---------------- src/bootstrap/src/core/build_steps/clippy.rs | 2 +- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f5dae626a89bd..fcd4f4078adb4 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -21,13 +21,6 @@ pub struct Std { /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc crates: Vec, - /// Override `Builder::kind` on cargo invocations. - /// - /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations. - /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`, - /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library, - /// which is not useful if we only want to lint a few crates with specific rules. - override_build_kind: Option, /// Never use this from outside calls. It is intended for internal use only within `check::Std::make_run` /// and `check::Std::run`. custom_stage: Option, @@ -37,12 +30,7 @@ impl Std { const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests"]; pub fn new(target: TargetSelection) -> Self { - Self { target, crates: vec![], override_build_kind: None, custom_stage: None } - } - - pub fn build_kind(mut self, kind: Option) -> Self { - self.override_build_kind = kind; - self + Self { target, crates: vec![], custom_stage: None } } } @@ -68,12 +56,7 @@ impl Step for Std { 1 }; - run.builder.ensure(Std { - target: run.target, - crates, - override_build_kind: None, - custom_stage: Some(stage), - }); + run.builder.ensure(Std { target: run.target, crates, custom_stage: Some(stage) }); } fn run(self, builder: &Builder<'_>) { @@ -116,7 +99,7 @@ impl Step for Std { Mode::Std, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); std_cargo(builder, target, compiler.stage, &mut cargo); @@ -147,9 +130,8 @@ impl Step for Std { } drop(_guard); - // don't run on std twice with x.py clippy // don't check test dependencies if we haven't built libtest - if builder.kind == Kind::Clippy || !self.crates.iter().any(|krate| krate == "test") { + if !self.crates.iter().any(|krate| krate == "test") { return; } @@ -165,7 +147,7 @@ impl Step for Std { Mode::Std, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); // If we're not in stage 0, tests and examples will fail to compile @@ -382,14 +364,9 @@ impl Step for RustAnalyzer { cargo.allow_features(crate::core::build_steps::tool::RustAnalyzer::ALLOW_FEATURES); - // For ./x.py clippy, don't check those targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - // can't use `--all-targets` because `--examples` doesn't work well - cargo.arg("--bins"); - cargo.arg("--tests"); - cargo.arg("--benches"); - } + cargo.arg("--bins"); + cargo.arg("--tests"); + cargo.arg("--benches"); // Cargo's output path in a given stage, compiled by a particular // compiler for the specified target. @@ -450,11 +427,7 @@ impl Step for Compiletest { cargo.allow_features(COMPILETEST_ALLOW_FEATURES); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } + cargo.arg("--all-targets"); let stamp = BuildStamp::new(&builder.cargo_out(compiler, mode, self.target)) .with_prefix("compiletest-check"); @@ -528,11 +501,7 @@ fn run_tool_check_step( &[], ); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } + cargo.arg("--all-targets"); let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target)) .with_prefix(&format!("{}-check", step_type_name.to_lowercase())); diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index f1932479d4679..ebf0caccfbc98 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -217,7 +217,7 @@ impl Step for Rustc { builder.ensure(compile::Std::new(compiler, compiler.host)); builder.ensure(compile::Std::new(compiler, target)); } else { - builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check))); + builder.ensure(check::Std::new(target)); } }