Skip to content

Commit cd10ec8

Browse files
Move error code explanation removal check into tidy
1 parent 1fb182b commit cd10ec8

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-require
3939

4040
COPY host-x86_64/mingw-check-1/check-default-config-profiles.sh /scripts/
4141
COPY host-x86_64/mingw-check-1/validate-toolstate.sh /scripts/
42-
COPY host-x86_64/mingw-check-1/validate-error-codes.sh /scripts/
4342

4443
# Check library crates on all tier 1 targets.
4544
# We disable optimized compiler built-ins because that requires a C toolchain for the target.
@@ -52,7 +51,6 @@ ENV SCRIPT \
5251
python3 ../x.py check --stage 1 --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
5352
python3 ../x.py check --stage 1 --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 && \
5453
/scripts/validate-toolstate.sh && \
55-
/scripts/validate-error-codes.sh && \
5654
reuse --include-submodules lint && \
5755
python3 ../x.py test collect-license-metadata && \
5856
# Runs checks to ensure that there are no issues in our JS code.

src/ci/docker/host-x86_64/mingw-check-1/validate-error-codes.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-require
3939
&& pip3 install virtualenv
4040

4141
COPY host-x86_64/mingw-check-1/validate-toolstate.sh /scripts/
42-
COPY host-x86_64/mingw-check-1/validate-error-codes.sh /scripts/
4342

4443
RUN bash -c 'npm install -g eslint@$(cat /tmp/eslint.version)'
4544

src/tools/tidy/src/error_codes.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ macro_rules! verbose_print {
4343
};
4444
}
4545

46-
pub fn check(root_path: &Path, search_paths: &[&Path], verbose: bool, bad: &mut bool) {
46+
pub fn check(
47+
root_path: &Path,
48+
search_paths: &[&Path],
49+
verbose: bool,
50+
ci_info: &crate::CiInfo,
51+
bad: &mut bool,
52+
) {
4753
let mut errors = Vec::new();
4854

55+
// Check that no error code explanation was removed.
56+
check_removed_error_code_explanation(ci_info, bad);
57+
4958
// Stage 1: create list
5059
let error_codes = extract_error_codes(root_path, &mut errors);
5160
if verbose {
@@ -68,6 +77,27 @@ pub fn check(root_path: &Path, search_paths: &[&Path], verbose: bool, bad: &mut
6877
}
6978
}
7079

80+
fn check_removed_error_code_explanation(ci_info: &crate::CiInfo, bad: &mut bool) {
81+
let Some(base_commit) = &ci_info.base_commit else {
82+
eprintln!("Skipping error code explanation removal check");
83+
return;
84+
};
85+
let Some(diff) = crate::git_diff(base_commit, "--name-status") else {
86+
*bad = true;
87+
eprintln!("removed error code explanation tidy check: Failed to run git diff");
88+
return;
89+
};
90+
if diff.lines().any(|line| {
91+
line.starts_with('D') && line.contains("compiler/rustc_error_codes/src/error_codes/")
92+
}) {
93+
*bad = true;
94+
eprintln!("tidy check error: Error code explanations should never be removed!");
95+
eprintln!("Take a look at E0001 to see how to handle it.");
96+
return;
97+
}
98+
println!("No error code explanation was removed!");
99+
}
100+
71101
/// Stage 1: Parses a list of error codes from `error_codes.rs`.
72102
fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String> {
73103
let path = root_path.join(Path::new(ERROR_CODES_PATH));

src/tools/tidy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn main() {
117117
check!(unknown_revision, &tests_path);
118118

119119
// Checks that only make sense for the compiler.
120-
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose);
120+
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose, &ci_info);
121121
check!(fluent_alphabetical, &compiler_path, bless);
122122
check!(fluent_period, &compiler_path);
123123
check!(target_policy, &root_path);

0 commit comments

Comments
 (0)