Skip to content

Commit b0cc98e

Browse files
pietroalbiniklensy
authored andcommitted
define all the clippy lints we check in CI in a step
1 parent 9e59969 commit b0cc98e

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

src/bootstrap/src/core/build_steps/clippy.rs

+68
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ impl LintConfig {
102102
_ => unreachable!("LintConfig can only be called from `clippy` subcommands."),
103103
}
104104
}
105+
106+
fn merge(&self, other: &Self) -> Self {
107+
let merged = |self_attr: &[String], other_attr: &[String]| -> Vec<String> {
108+
self_attr.iter().cloned().chain(other_attr.iter().cloned()).collect()
109+
};
110+
// This is written this way to ensure we get a compiler error if we add a new field.
111+
Self {
112+
allow: merged(&self.allow, &other.allow),
113+
warn: merged(&self.warn, &other.warn),
114+
deny: merged(&self.deny, &other.deny),
115+
forbid: merged(&self.forbid, &other.forbid),
116+
}
117+
}
105118
}
106119

107120
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -339,3 +352,58 @@ lint_any!(
339352
Tidy, "src/tools/tidy", "tidy";
340353
TestFloatParse, "src/etc/test-float-parse", "test-float-parse";
341354
);
355+
356+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
357+
pub struct CI {
358+
target: TargetSelection,
359+
config: LintConfig,
360+
}
361+
362+
impl Step for CI {
363+
type Output = ();
364+
const DEFAULT: bool = false;
365+
366+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
367+
run.alias("ci")
368+
}
369+
370+
fn make_run(run: RunConfig<'_>) {
371+
let config = LintConfig::new(run.builder);
372+
run.builder.ensure(CI { target: run.target, config });
373+
}
374+
375+
fn run(self, builder: &Builder<'_>) -> Self::Output {
376+
builder.ensure(Bootstrap {
377+
target: self.target,
378+
config: self.config.merge(&LintConfig {
379+
allow: vec![],
380+
warn: vec![],
381+
deny: vec!["warnings".into()],
382+
forbid: vec![],
383+
}),
384+
});
385+
let library_clippy_cfg = LintConfig {
386+
allow: vec!["clippy::all".into()],
387+
warn: vec![],
388+
deny: vec!["clippy::correctness".into()],
389+
forbid: vec![],
390+
};
391+
let compiler_clippy_cfg = LintConfig {
392+
allow: vec!["clippy::all".into()],
393+
warn: vec![],
394+
deny: vec!["clippy::correctness".into(), "clippy::clone_on_ref_ptr".into()],
395+
forbid: vec![],
396+
};
397+
398+
builder.ensure(Std {
399+
target: self.target,
400+
config: self.config.merge(&library_clippy_cfg),
401+
crates: vec![],
402+
});
403+
builder.ensure(Rustc {
404+
target: self.target,
405+
config: self.config.merge(&compiler_clippy_cfg),
406+
crates: vec![],
407+
});
408+
}
409+
}

src/bootstrap/src/core/builder/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ impl<'a> Builder<'a> {
839839
clippy::RustInstaller,
840840
clippy::TestFloatParse,
841841
clippy::Tidy,
842+
clippy::CI,
842843
),
843844
Kind::Check | Kind::Fix => describe!(
844845
check::Std,

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ ENV SCRIPT \
5050
python3 ../x.py check --stage 0 --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \
5151
/scripts/check-default-config-profiles.sh && \
5252
python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
53-
python3 ../x.py clippy bootstrap -Dwarnings && \
54-
python3 ../x.py clippy library -Aclippy::all -Dclippy::correctness && \
55-
python3 ../x.py clippy compiler -Aclippy::all -Dclippy::correctness -Dclippy::clone_on_ref_ptr && \
53+
python3 ../x.py clippy ci && \
5654
python3 ../x.py build --stage 0 src/tools/build-manifest && \
5755
python3 ../x.py test --stage 0 src/tools/compiletest && \
5856
python3 ../x.py test --stage 0 core alloc std test proc_macro && \

0 commit comments

Comments
 (0)