`rustc_errors` depends on numerous crates, solely to implement its `IntoDiagArg` trait on types from those crates. Many crates depend on `rustc_errors`, and it's on the critical path. We can't swap things around to make all of those crates depend on `rustc_errors` instead, because `rustc_errors` would end up in dependency cycles. Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far fewer dependencies, and then have most of these crates depend on `rustc_error_messages`. This allows `rustc_errors` to drop dependencies on several crates, including the large `rustc_target`. (This doesn't fully reduce dependency chains yet, as `rustc_errors` still depends on `rustc_hir` which depends on `rustc_target`. That will get fixed in a subsequent commit.)
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
//! This module defines the following.
|
|
//! - The `ErrCode` type.
|
|
//! - A constant for every error code, with a name like `E0123`.
|
|
//! - A static table `DIAGNOSTICS` pairing every error code constant with its
|
|
//! long description text.
|
|
|
|
use std::fmt;
|
|
|
|
rustc_index::newtype_index! {
|
|
#[max = 9999] // Because all error codes have four digits.
|
|
#[orderable]
|
|
#[encodable]
|
|
#[debug_format = "ErrCode({})"]
|
|
pub struct ErrCode {}
|
|
}
|
|
|
|
impl fmt::Display for ErrCode {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "E{:04}", self.as_u32())
|
|
}
|
|
}
|
|
|
|
rustc_error_messages::into_diag_arg_using_display!(ErrCode);
|
|
|
|
macro_rules! define_error_code_constants_and_diagnostics_table {
|
|
($($name:ident: $num:literal,)*) => (
|
|
$(
|
|
pub const $name: $crate::ErrCode = $crate::ErrCode::from_u32($num);
|
|
)*
|
|
pub static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
|
|
$( (
|
|
$name,
|
|
include_str!(
|
|
concat!("../../rustc_error_codes/src/error_codes/", stringify!($name), ".md")
|
|
)
|
|
), )*
|
|
];
|
|
)
|
|
}
|
|
|
|
rustc_error_codes::error_codes!(define_error_code_constants_and_diagnostics_table);
|