Skip to content

Commit 865d0c6

Browse files
Fix error codes check run and ensure it will not go unnoticed again
1 parent 2b8fbe6 commit 865d0c6

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/tools/tidy/src/error_codes_check.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fn check_error_code_explanation(
4848
}
4949

5050
fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
51+
let mut ignore_found = false;
52+
5153
for line in f.lines() {
5254
let s = line.trim();
5355
if s.starts_with("#### Note: this error code is no longer emitted by the compiler") {
@@ -56,13 +58,13 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
5658
if s.starts_with("```") {
5759
if s.contains("compile_fail") && s.contains(err_code) {
5860
return true;
59-
} else if s.contains('(') {
61+
} else if s.contains("ignore") {
6062
// It's very likely that we can't actually make it fail compilation...
61-
return true;
63+
ignore_found = true;
6264
}
6365
}
6466
}
65-
false
67+
ignore_found
6668
}
6769

6870
macro_rules! some_or_continue {
@@ -164,18 +166,32 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap<String, boo
164166
}
165167
}
166168

167-
pub fn check(path: &Path, bad: &mut bool) {
169+
pub fn check(paths: &[&Path], bad: &mut bool) {
168170
let mut errors = Vec::new();
171+
let mut found_explanations = 0;
172+
let mut found_tests = 0;
169173
println!("Checking which error codes lack tests...");
170174
let mut error_codes: HashMap<String, bool> = HashMap::new();
171-
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
172-
let file_name = entry.file_name();
173-
if file_name == "error_codes.rs" {
174-
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
175-
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
176-
extract_error_codes_from_tests(contents, &mut error_codes);
177-
}
178-
});
175+
for path in paths {
176+
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
177+
let file_name = entry.file_name();
178+
if file_name == "error_codes.rs" {
179+
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
180+
found_explanations += 1;
181+
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
182+
extract_error_codes_from_tests(contents, &mut error_codes);
183+
found_tests += 1;
184+
}
185+
});
186+
}
187+
if found_explanations == 0 {
188+
eprintln!("No error code explanation was tested!");
189+
*bad = true;
190+
}
191+
if found_tests == 0 {
192+
eprintln!("No error code was found in compilation errors!");
193+
*bad = true;
194+
}
179195
if errors.is_empty() {
180196
println!("Found {} error codes", error_codes.len());
181197

src/tools/tidy/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131

3232
// Checks that only make sense for the compiler.
3333
errors::check(&compiler_path, &mut bad);
34-
error_codes_check::check(&src_path, &mut bad);
34+
error_codes_check::check(&[&src_path, &compiler_path], &mut bad);
3535

3636
// Checks that only make sense for the std libs.
3737
pal::check(&library_path, &mut bad);

0 commit comments

Comments
 (0)