1
Fork 0

errors: generate typed identifiers in each crate

Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-10-13 10:13:02 +01:00
parent f9216b7564
commit d1fcf61117
151 changed files with 1721 additions and 1440 deletions

View file

@ -11,6 +11,9 @@
#[macro_use]
extern crate rustc_macros;
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_macros::fluent_messages;
mod builtin;
mod session_diagnostics;
@ -22,3 +25,5 @@ pub use StabilityLevel::*;
pub use rustc_ast::attr::*;
pub(crate) use rustc_ast::HashStableContext;
fluent_messages! { "../locales/en-US.ftl" }

View file

@ -2,11 +2,12 @@ use std::num::IntErrorKind;
use rustc_ast as ast;
use rustc_errors::{
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
use crate::fluent_generated as fluent;
use crate::UnsupportedLiteralReason;
#[derive(Diagnostic)]
@ -59,7 +60,7 @@ impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> {
);
diag.set_arg("item", self.item);
diag.set_arg("expected", expected.join(", "));
diag.span_label(self.span, fluent::label);
diag.span_label(self.span, fluent::attr_label);
diag
}
}
@ -99,31 +100,31 @@ pub(crate) struct InvalidIssueString {
// translatable.
#[derive(Subdiagnostic)]
pub(crate) enum InvalidIssueStringCause {
#[label(must_not_be_zero)]
#[label(attr_must_not_be_zero)]
MustNotBeZero {
#[primary_span]
span: Span,
},
#[label(empty)]
#[label(attr_empty)]
Empty {
#[primary_span]
span: Span,
},
#[label(invalid_digit)]
#[label(attr_invalid_digit)]
InvalidDigit {
#[primary_span]
span: Span,
},
#[label(pos_overflow)]
#[label(attr_pos_overflow)]
PosOverflow {
#[primary_span]
span: Span,
},
#[label(neg_overflow)]
#[label(attr_neg_overflow)]
NegOverflow {
#[primary_span]
span: Span,
@ -275,7 +276,7 @@ pub(crate) struct IncorrectReprFormatGeneric<'a> {
#[derive(Subdiagnostic)]
pub(crate) enum IncorrectReprFormatGenericCause<'a> {
#[suggestion(suggestion, code = "{name}({int})", applicability = "machine-applicable")]
#[suggestion(attr_suggestion, code = "{name}({int})", applicability = "machine-applicable")]
Int {
#[primary_span]
span: Span,
@ -287,7 +288,7 @@ pub(crate) enum IncorrectReprFormatGenericCause<'a> {
int: u128,
},
#[suggestion(suggestion, code = "{name}({symbol})", applicability = "machine-applicable")]
#[suggestion(attr_suggestion, code = "{name}({symbol})", applicability = "machine-applicable")]
Symbol {
#[primary_span]
span: Span,