Stop using String
for error codes.
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.
This commit is contained in:
parent
0321de2778
commit
5d9dfbd08f
110 changed files with 1624 additions and 1572 deletions
|
@ -1,9 +1,9 @@
|
|||
use rustc_errors::DiagnosticArgFromDisplay;
|
||||
use rustc_errors::{codes::*, DiagnosticArgFromDisplay};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
|
||||
#[diag(ast_lowering_generic_type_with_parentheses, code = E0214)]
|
||||
pub struct GenericTypeWithParentheses {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
|
@ -22,7 +22,7 @@ pub struct UseAngleBrackets {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_lowering_invalid_abi, code = "E0703")]
|
||||
#[diag(ast_lowering_invalid_abi, code = E0703)]
|
||||
#[note]
|
||||
pub struct InvalidAbi {
|
||||
#[primary_span]
|
||||
|
@ -89,7 +89,7 @@ pub enum AssocTyParenthesesSub {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
|
||||
#[diag(ast_lowering_misplaced_impl_trait, code = E0562)]
|
||||
#[note]
|
||||
pub struct MisplacedImplTrait<'a> {
|
||||
#[primary_span]
|
||||
|
@ -114,7 +114,7 @@ pub struct UnderscoreExprLhsAssign {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
|
||||
#[diag(ast_lowering_base_expression_double_dot, code = E0797)]
|
||||
pub struct BaseExpressionDoubleDot {
|
||||
#[primary_span]
|
||||
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
|
||||
|
@ -122,7 +122,7 @@ pub struct BaseExpressionDoubleDot {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
|
||||
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)]
|
||||
pub struct AwaitOnlyInAsyncFnAndBlocks {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
|
@ -132,14 +132,14 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
|
||||
#[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)]
|
||||
pub struct CoroutineTooManyParameters {
|
||||
#[primary_span]
|
||||
pub fn_decl_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
|
||||
#[diag(ast_lowering_closure_cannot_be_static, code = E0697)]
|
||||
pub struct ClosureCannotBeStatic {
|
||||
#[primary_span]
|
||||
pub fn_decl_span: Span,
|
||||
|
@ -154,14 +154,14 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
|
||||
#[diag(ast_lowering_async_coroutines_not_supported, code = E0727)]
|
||||
pub struct AsyncCoroutinesNotSupported {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic, Clone, Copy)]
|
||||
#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
|
||||
#[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)]
|
||||
pub struct InlineAsmUnsupportedTarget {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue