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
This commit is contained in:
Matthias Krüger
2024-04-09 06:02:21 +02:00
committed by GitHub
10 changed files with 109 additions and 61 deletions
+31 -14
View File
@@ -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!(
"`{}:` should be followed by `{}` but instead found `{}` in \
"{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!(
"{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;