Auto merge of #83451 - GuillaumeGomez:fix-error-code-tidy-check, r=Mark-Simulacrum

Fix error codes check run and ensure it will not go unnoticed again

Fixes #83268.

The error codes explanations were not checked anymore. I fixed this issue and also added variables to ensure that this won't happen again (at least not silently).
This commit is contained in:
bors 2021-04-04 15:34:01 +00:00
commit 5b0ab79116
2 changed files with 29 additions and 13 deletions

View file

@ -48,6 +48,8 @@ fn check_error_code_explanation(
}
fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
let mut ignore_found = false;
for line in f.lines() {
let s = line.trim();
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 {
if s.starts_with("```") {
if s.contains("compile_fail") && s.contains(err_code) {
return true;
} else if s.contains('(') {
} else if s.contains("ignore") {
// It's very likely that we can't actually make it fail compilation...
return true;
ignore_found = true;
}
}
}
false
ignore_found
}
macro_rules! some_or_continue {
@ -164,18 +166,32 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap<String, boo
}
}
pub fn check(path: &Path, bad: &mut bool) {
pub fn check(paths: &[&Path], bad: &mut bool) {
let mut errors = Vec::new();
let mut found_explanations = 0;
let mut found_tests = 0;
println!("Checking which error codes lack tests...");
let mut error_codes: HashMap<String, bool> = HashMap::new();
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
let file_name = entry.file_name();
if file_name == "error_codes.rs" {
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
extract_error_codes_from_tests(contents, &mut error_codes);
}
});
for path in paths {
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
let file_name = entry.file_name();
if file_name == "error_codes.rs" {
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
found_explanations += 1;
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
extract_error_codes_from_tests(contents, &mut error_codes);
found_tests += 1;
}
});
}
if found_explanations == 0 {
eprintln!("No error code explanation was tested!");
*bad = true;
}
if found_tests == 0 {
eprintln!("No error code was found in compilation errors!");
*bad = true;
}
if errors.is_empty() {
println!("Found {} error codes", error_codes.len());

View file

@ -65,7 +65,7 @@ fn main() {
// Checks that only make sense for the compiler.
check!(errors, &compiler_path);
check!(error_codes_check, &src_path);
check!(error_codes_check, &[&src_path, &compiler_path]);
// Checks that only make sense for the std libs.
check!(pal, &library_path);