about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-09 06:02:21 +0200
committerGitHub <noreply@github.com>2024-04-09 06:02:21 +0200
commit643dee7573fcbb0f903acab08cefddffbcbf7f2d (patch)
tree2c4b67c8b62c81b004c7b73b903fea34cdb0f48e /src/tools
parent59c808fcd9eeb3c5528209d1cef3aaa5521edbd6 (diff)
parent7f9a4af0eb498bd0b1bcd7b6124ed90a1f7fac7b (diff)
downloadrust-643dee7573fcbb0f903acab08cefddffbcbf7f2d.tar.gz
rust-643dee7573fcbb0f903acab08cefddffbcbf7f2d.zip
Rollup merge of #122768 - oli-obk:why_is_E0699_so_bad, r=WaffleLapkin
Use the more informative generic type inference failure error on method calls on raw pointers
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/tidy/src/error_codes.rs45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs
index 6fc65e56901..39f7e70b693 100644
--- a/src/tools/tidy/src/error_codes.rs
+++ b/src/tools/tidy/src/error_codes.rs
@@ -71,10 +71,12 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
     let path = root_path.join(Path::new(ERROR_CODES_PATH));
     let file =
         fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read `{path:?}`: {e}"));
+    let path = path.display();
 
     let mut error_codes = Vec::new();
 
-    for line in file.lines() {
+    for (line_index, line) in file.lines().enumerate() {
+        let line_index = line_index + 1;
         let line = line.trim();
 
         if line.starts_with('E') {
@@ -82,39 +84,54 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
 
             // Extract the error code from the line. Emit a fatal error if it is not in the correct
             // format.
-            let err_code = if let Some(err_code) = split_line {
-                err_code.0.to_owned()
-            } else {
+            let Some(split_line) = split_line else {
                 errors.push(format!(
-                    "Expected a line with the format `Eabcd: abcd, \
+                    "{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
                     but got \"{}\" without a `:` delimiter",
                     line,
                 ));
                 continue;
             };
 
+            let err_code = split_line.0.to_owned();
+
             // If this is a duplicate of another error code, emit a fatal error.
             if error_codes.contains(&err_code) {
-                errors.push(format!("Found duplicate error code: `{}`", err_code));
+                errors.push(format!(
+                    "{path}:{line_index}: Found duplicate error code: `{}`",
+                    err_code
+                ));
                 continue;
             }
 
             let mut chars = err_code.chars();
-            chars.next();
+            assert_eq!(chars.next(), Some('E'));
             let error_num_as_str = chars.as_str();
 
             // Ensure that the line references the correct markdown file.
-            let expected_filename = format!(" {},", error_num_as_str);
-            if expected_filename != split_line.unwrap().1 {
+            let rest = split_line.1.split_once(',');
+            let Some(rest) = rest else {
+                errors.push(format!(
+                    "{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
+                    but got \"{}\" without a `,` delimiter",
+                    line,
+                ));
+                continue;
+            };
+            if error_num_as_str != rest.0.trim() {
                 errors.push(format!(
-                    "`{}:` should be followed by `{}` but instead found `{}` in \
+                    "{path}:{line_index}: `{}:` should be followed by `{},` but instead found `{}` in \
                     `compiler/rustc_error_codes/src/lib.rs`",
                     err_code,
-                    expected_filename,
-                    split_line.unwrap().1,
+                    error_num_as_str,
+                    split_line.1,
                 ));
                 continue;
             }
+            if !rest.1.trim().is_empty() && !rest.1.trim().starts_with("//") {
+                errors.push(format!("{path}:{line_index}: should only have one error per line"));
+                continue;
+            }
 
             error_codes.push(err_code);
         }
@@ -146,14 +163,14 @@ fn check_error_codes_docs(
             return;
         }
 
-        // Make sure that the file is referenced in `error_codes.rs`
+        // Make sure that the file is referenced in `rustc_error_codes/src/lib.rs`
         let filename = path.file_name().unwrap().to_str().unwrap().split_once('.');
         let err_code = filename.unwrap().0; // `unwrap` is ok because we know the filename is in the correct format.
 
         if error_codes.iter().all(|e| e != err_code) {
             errors.push(format!(
                 "Found valid file `{}` in error code docs directory without corresponding \
-                entry in `error_code.rs`",
+                entry in `rustc_error_codes/src/lib.rs`",
                 path.display()
             ));
             return;