5d9dfbd08f
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.
110 lines
3.1 KiB
Rust
110 lines
3.1 KiB
Rust
use crate::fluent_generated as fluent;
|
|
use rustc_errors::{codes::*, AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
|
use rustc_session::lint::Level;
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_overruled_attribute, code = E0453)]
|
|
pub struct OverruledAttribute<'a> {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
#[label]
|
|
pub overruled: Span,
|
|
pub lint_level: &'a str,
|
|
pub lint_source: Symbol,
|
|
#[subdiagnostic]
|
|
pub sub: OverruledAttributeSub,
|
|
}
|
|
//
|
|
pub enum OverruledAttributeSub {
|
|
DefaultSource { id: String },
|
|
NodeSource { span: Span, reason: Option<Symbol> },
|
|
CommandLineSource,
|
|
}
|
|
|
|
impl AddToDiagnostic for OverruledAttributeSub {
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
where
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
{
|
|
match self {
|
|
OverruledAttributeSub::DefaultSource { id } => {
|
|
diag.note(fluent::lint_default_source);
|
|
diag.arg("id", id);
|
|
}
|
|
OverruledAttributeSub::NodeSource { span, reason } => {
|
|
diag.span_label(span, fluent::lint_node_source);
|
|
if let Some(rationale) = reason {
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
|
diag.note(rationale.to_string());
|
|
}
|
|
}
|
|
OverruledAttributeSub::CommandLineSource => {
|
|
diag.note(fluent::lint_command_line_source);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_malformed_attribute, code = E0452)]
|
|
pub struct MalformedAttribute {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
#[subdiagnostic]
|
|
pub sub: MalformedAttributeSub,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
pub enum MalformedAttributeSub {
|
|
#[label(lint_bad_attribute_argument)]
|
|
BadAttributeArgument(#[primary_span] Span),
|
|
#[label(lint_reason_must_be_string_literal)]
|
|
ReasonMustBeStringLiteral(#[primary_span] Span),
|
|
#[label(lint_reason_must_come_last)]
|
|
ReasonMustComeLast(#[primary_span] Span),
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
|
|
pub struct UnknownToolInScopedLint {
|
|
#[primary_span]
|
|
pub span: Option<Span>,
|
|
pub tool_name: Symbol,
|
|
pub lint_name: String,
|
|
#[help]
|
|
pub is_nightly_build: Option<()>,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
|
|
pub struct BuiltinEllipsisInclusiveRangePatterns {
|
|
#[primary_span]
|
|
pub span: Span,
|
|
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
|
|
pub suggestion: Span,
|
|
pub replace: String,
|
|
}
|
|
|
|
#[derive(Subdiagnostic)]
|
|
#[note(lint_requested_level)]
|
|
pub struct RequestedLevel<'a> {
|
|
pub level: Level,
|
|
pub lint_name: &'a str,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_unsupported_group, code = E0602)]
|
|
pub struct UnsupportedGroup {
|
|
pub lint_group: String,
|
|
}
|
|
|
|
#[derive(Diagnostic)]
|
|
#[diag(lint_check_name_unknown_tool, code = E0602)]
|
|
pub struct CheckNameUnknownTool<'a> {
|
|
pub tool_name: Symbol,
|
|
#[subdiagnostic]
|
|
pub sub: RequestedLevel<'a>,
|
|
}
|