Skip to content

Commit

Permalink
Auto merge of rust-lang#85786 - GuillaumeGomez:error-code-checker-imp…
Browse files Browse the repository at this point in the history
…rovement, r=Mark-Simulacrum

Error code checker improvement

Just realized that some error codes shouldn't be ignored anymore. So I updated the script to ensure that if an error code is tested and ignored, it will trigger an error.
  • Loading branch information
bors committed May 30, 2021
2 parents bff138d + 7602818 commit d93b6a4
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/tools/tidy/src/error_codes_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use std::path::Path;

// A few of those error codes can't be tested but all the others can and *should* be tested!
const EXEMPTED_FROM_TEST: &[&str] = &[
"E0183", "E0227", "E0279", "E0280", "E0311", "E0313", "E0314", "E0315", "E0377", "E0461",
"E0462", "E0464", "E0465", "E0472", "E0473", "E0474", "E0475", "E0476", "E0479", "E0480",
"E0481", "E0482", "E0483", "E0484", "E0485", "E0486", "E0487", "E0488", "E0489", "E0514",
"E0519", "E0523", "E0553", "E0554", "E0570", "E0629", "E0630", "E0640", "E0717", "E0727",
"E0729",
"E0227", "E0279", "E0280", "E0313", "E0314", "E0315", "E0377", "E0461", "E0462", "E0464",
"E0465", "E0473", "E0474", "E0475", "E0476", "E0479", "E0480", "E0481", "E0482", "E0483",
"E0484", "E0485", "E0486", "E0487", "E0488", "E0489", "E0514", "E0519", "E0523", "E0553",
"E0554", "E0570", "E0629", "E0630", "E0640", "E0717", "E0729",
];

// Some error codes don't have any tests apparently...
const IGNORE_EXPLANATION_CHECK: &[&str] = &["E0570", "E0601", "E0602", "E0639", "E0729"];
const IGNORE_EXPLANATION_CHECK: &[&str] = &["E0570", "E0601", "E0602", "E0729"];

fn check_error_code_explanation(
f: &str,
Expand Down Expand Up @@ -114,13 +113,18 @@ fn extract_error_codes(
.expect("failed to canonicalize error explanation file path");
match read_to_string(&path) {
Ok(content) => {
if !IGNORE_EXPLANATION_CHECK.contains(&err_code.as_str())
&& !check_if_error_code_is_test_in_explanation(&content, &err_code)
{
let has_test = check_if_error_code_is_test_in_explanation(&content, &err_code);
if !has_test && !IGNORE_EXPLANATION_CHECK.contains(&err_code.as_str()) {
errors.push(format!(
"`{}` doesn't use its own error code in compile_fail example",
path.display(),
));
} else if has_test && IGNORE_EXPLANATION_CHECK.contains(&err_code.as_str()) {
errors.push(format!(
"`{}` has a compile_fail example with its own error code, it shouldn't \
be listed in IGNORE_EXPLANATION_CHECK!",
path.display(),
));
}
if check_error_code_explanation(&content, error_codes, err_code) {
errors.push(format!(
Expand Down Expand Up @@ -198,6 +202,11 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
for (err_code, nb) in &error_codes {
if !*nb && !EXEMPTED_FROM_TEST.contains(&err_code.as_str()) {
errors.push(format!("Error code {} needs to have at least one UI test!", err_code));
} else if *nb && EXEMPTED_FROM_TEST.contains(&err_code.as_str()) {
errors.push(format!(
"Error code {} has a UI test, it shouldn't be listed into EXEMPTED_FROM_TEST!",
err_code
));
}
}
}
Expand Down

0 comments on commit d93b6a4

Please sign in to comment.