about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-04 15:34:01 +0000
committerbors <bors@rust-lang.org>2021-04-04 15:34:01 +0000
commit5b0ab79116ba3231f447bc7a67c16ce93ecca0a3 (patch)
tree74f5f055453480c7eb583e98b14edffe469e8a3a
parentb1ea2618d3fef50981c566564cf234b4b98f6328 (diff)
parenta41d41cbc66b81111704a8787bf408b78de7730d (diff)
downloadrust-5b0ab79116ba3231f447bc7a67c16ce93ecca0a3.tar.gz
rust-5b0ab79116ba3231f447bc7a67c16ce93ecca0a3.zip
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).
-rw-r--r--src/tools/tidy/src/error_codes_check.rs40
-rw-r--r--src/tools/tidy/src/main.rs2
2 files changed, 29 insertions, 13 deletions
diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs
index a7199fdfce6..55f824b63f2 100644
--- a/src/tools/tidy/src/error_codes_check.rs
+++ b/src/tools/tidy/src/error_codes_check.rs
@@ -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());
 
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index f190a9e57ce..10356a2fdc5 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -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);