Rollup merge of #146584 - cyrgani:error-codes-macro, r=GuillaumeGomez

remove duplicated columns from `rustc_error_code::error_codes!`

Possible because of rust-lang/rust#146308 ~~, but currently still blocked on the next stage0 bump~~.
This commit is contained in:
Matthias Krüger 2025-12-11 22:09:52 +01:00 committed by GitHub
commit bf399241fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 535 additions and 562 deletions

View file

@ -1,4 +1,4 @@
#### this error code is no longer emitted by the compiler.
#### Note: this error code is no longer emitted by the compiler.
This was triggered when multiple macro definitions used the same
`#[rustc_builtin_macro(..)]`. This is no longer an error.

File diff suppressed because it is too large Load diff

View file

@ -23,15 +23,15 @@ impl fmt::Display for ErrCode {
rustc_error_messages::into_diag_arg_using_display!(ErrCode);
macro_rules! define_error_code_constants_and_diagnostics_table {
($($name:ident: $num:literal,)*) => (
($($num:literal,)*) => (
$(
pub const $name: $crate::ErrCode = $crate::ErrCode::from_u32($num);
pub const ${concat(E, $num)}: $crate::ErrCode = $crate::ErrCode::from_u32($num);
)*
pub static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
$( (
$name,
${concat(E, $num)},
include_str!(
concat!("../../rustc_error_codes/src/error_codes/", stringify!($name), ".md")
concat!("../../rustc_error_codes/src/error_codes/E", stringify!($num), ".md")
)
), )*
];

View file

@ -13,6 +13,7 @@
#![feature(box_patterns)]
#![feature(default_field_values)]
#![feature(error_reporter)]
#![feature(macro_metavar_expr_concat)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(rustc_attrs)]

View file

@ -91,20 +91,16 @@ fn extract_error_codes(root_path: &Path, check: &mut RunningCheck) -> Vec<String
let line_index = line_index + 1;
let line = line.trim();
if line.starts_with('E') {
let split_line = line.split_once(':');
// Extract the error code from the line. Emit a fatal error if it is not in the correct
// format.
let Some(split_line) = split_line else {
if line.starts_with(|c: char| c.is_ascii_digit()) {
let mut chars = line.chars();
let err_code = chars.by_ref().take(4).collect::<String>();
if chars.next() != Some(',') {
check.error(format!(
"{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
but got \"{line}\" without a `:` delimiter",
"{path}:{line_index}: Expected a line with the format `abcd,` \
but got \"{line}\" without a `,` delimiter",
));
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) {
@ -114,35 +110,13 @@ fn extract_error_codes(root_path: &Path, check: &mut RunningCheck) -> Vec<String
continue;
}
let mut chars = err_code.chars();
assert_eq!(chars.next(), Some('E'));
let error_num_as_str = chars.as_str();
// Ensure that the line references the correct markdown file.
let rest = split_line.1.split_once(',');
let Some(rest) = rest else {
check.error(format!(
"{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
but got \"{line}\" without a `,` delimiter",
));
continue;
};
if error_num_as_str != rest.0.trim() {
check.error(format!(
"{path}:{line_index}: `{}:` should be followed by `{},` but instead found `{}` in \
`compiler/rustc_error_codes/src/lib.rs`",
err_code,
error_num_as_str,
split_line.1,
));
continue;
}
if !rest.1.trim().is_empty() && !rest.1.trim().starts_with("//") {
let rest = chars.as_str().trim();
if !rest.is_empty() && !rest.starts_with("//") {
check.error(format!("{path}:{line_index}: should only have one error per line"));
continue;
}
error_codes.push(err_code);
error_codes.push(format!("E{err_code}"));
}
}