mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 12:07:40 +00:00

Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
98 lines
2.1 KiB
Rust
98 lines
2.1 KiB
Rust
use rustc_errors::codes::*;
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
|
use rustc_session::Limit;
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
#[derive(Subdiagnostic)]
|
|
#[note(query_system_cycle_stack_middle)]
|
|
pub struct CycleStack {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
pub desc: String,
|
|
}
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub enum HandleCycleError {
|
|
Error,
|
|
Fatal,
|
|
DelayBug,
|
|
Stash,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
pub enum StackCount {
|
|
#[note(query_system_cycle_stack_single)]
|
|
Single,
|
|
#[note(query_system_cycle_stack_multiple)]
|
|
Multiple,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
pub enum Alias {
|
|
#[note(query_system_cycle_recursive_ty_alias)]
|
|
#[help(query_system_cycle_recursive_ty_alias_help1)]
|
|
#[help(query_system_cycle_recursive_ty_alias_help2)]
|
|
Ty,
|
|
#[note(query_system_cycle_recursive_trait_alias)]
|
|
Trait,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
#[note(query_system_cycle_usage)]
|
|
pub struct CycleUsage {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
pub usage: String,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(query_system_cycle, code = E0391)]
|
|
pub struct Cycle {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
pub stack_bottom: String,
|
|
#[subdiagnostic]
|
|
pub cycle_stack: Vec<CycleStack>,
|
|
#[subdiagnostic]
|
|
pub stack_count: StackCount,
|
|
#[subdiagnostic]
|
|
pub alias: Option<Alias>,
|
|
#[subdiagnostic]
|
|
pub cycle_usage: Option<CycleUsage>,
|
|
#[note]
|
|
pub note_span: (),
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(query_system_reentrant)]
|
|
pub struct Reentrant;
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(query_system_increment_compilation)]
|
|
#[help]
|
|
#[note(query_system_increment_compilation_note1)]
|
|
#[note(query_system_increment_compilation_note2)]
|
|
pub struct IncrementCompilation {
|
|
pub run_cmd: String,
|
|
pub dep_node: String,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[help]
|
|
#[diag(query_system_query_overflow)]
|
|
pub struct QueryOverflow {
|
|
#[primary_span]
|
|
pub span: Option<Span>,
|
|
#[subdiagnostic]
|
|
pub layout_of_depth: Option<LayoutOfDepth>,
|
|
pub suggested_limit: Limit,
|
|
pub crate_name: Symbol,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
#[note(query_system_layout_of_depth)]
|
|
pub struct LayoutOfDepth {
|
|
pub desc: String,
|
|
pub depth: usize,
|
|
}
|