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

@ -1,6 +1,6 @@
use hir::GenericParamKind;
use rustc_errors::{
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString,
AddToDiagnostic, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString,
IntoDiagnosticArg, MultiSpan, SubdiagnosticMessage,
};
use rustc_hir as hir;
@ -12,9 +12,10 @@ use rustc_span::symbol::kw;
use rustc_span::Symbol;
use rustc_span::{symbol::Ident, BytePos, Span};
use crate::infer::error_reporting::nice_region_error::placeholder_error::Highlighted;
use crate::fluent_generated as fluent;
use crate::infer::error_reporting::{
need_type_info::{GeneratorKindAsDiagArg, UnderspecifiedArgKind},
nice_region_error::placeholder_error::Highlighted,
ObligationCauseAsDiagArg,
};
@ -26,9 +27,9 @@ pub struct OpaqueHiddenTypeDiag {
#[primary_span]
#[label]
pub span: Span,
#[note(opaque_type)]
#[note(infer_opaque_type)]
pub opaque_type: Span,
#[note(hidden_type)]
#[note(infer_hidden_type)]
pub hidden_type: Span,
}
@ -768,11 +769,11 @@ impl<'tcx> ActualImplExplNotes<'tcx> {
pub struct TraitPlaceholderMismatch<'tcx> {
#[primary_span]
pub span: Span,
#[label(label_satisfy)]
#[label(infer_label_satisfy)]
pub satisfy_span: Option<Span>,
#[label(label_where)]
#[label(infer_label_where)]
pub where_span: Option<Span>,
#[label(label_dup)]
#[label(infer_label_dup)]
pub dup_span: Option<Span>,
pub def_id: String,
pub trait_def_id: String,
@ -808,11 +809,11 @@ pub struct RelationshipHelp;
#[diag(infer_trait_impl_diff)]
pub struct TraitImplDiff {
#[primary_span]
#[label(found)]
#[label(infer_found)]
pub sp: Span,
#[label(expected)]
#[label(infer_expected)]
pub trait_sp: Span,
#[note(expected_found)]
#[note(infer_expected_found)]
pub note: (),
#[subdiagnostic]
pub param_help: ConsiderBorrowingParamHelp,
@ -852,10 +853,10 @@ impl AddToDiagnostic for DynTraitConstraintSuggestion {
#[derive(Diagnostic)]
#[diag(infer_but_calling_introduces, code = "E0772")]
pub struct ButCallingIntroduces {
#[label(label1)]
#[label(infer_label1)]
pub param_ty_span: Span,
#[primary_span]
#[label(label2)]
#[label(infer_label2)]
pub cause_span: Span,
pub has_param_name: bool,
@ -913,15 +914,15 @@ impl AddToDiagnostic for MoreTargeted {
pub struct ButNeedsToSatisfy {
#[primary_span]
pub sp: Span,
#[label(influencer)]
#[label(infer_influencer)]
pub influencer_point: Span,
#[label(used_here)]
#[label(infer_used_here)]
pub spans: Vec<Span>,
#[label(require)]
#[label(infer_require)]
pub require_span_as_label: Option<Span>,
#[note(require)]
#[note(infer_require)]
pub require_span_as_note: Option<Span>,
#[note(introduced_by_bound)]
#[note(infer_introduced_by_bound)]
pub bound: Option<Span>,
#[subdiagnostic]

View file

@ -1,7 +1,6 @@
use crate::fluent_generated as fluent;
use crate::infer::error_reporting::nice_region_error::find_anon_type;
use rustc_errors::{
self, fluent, AddToDiagnostic, Diagnostic, IntoDiagnosticArg, SubdiagnosticMessage,
};
use rustc_errors::{self, AddToDiagnostic, Diagnostic, IntoDiagnosticArg, SubdiagnosticMessage};
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::kw, Span};

View file

@ -2,10 +2,11 @@ use crate::errors::{
note_and_explain, FullfillReqLifetime, LfBoundNotSatisfied, OutlivesBound, OutlivesContent,
RefLongerThanData, RegionOriginNote, WhereClauseSuggestions,
};
use crate::fluent_generated as fluent;
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
use crate::infer::{self, SubregionOrigin};
use rustc_errors::{
fluent, AddToDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
AddToDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::traits::ObligationCauseCode;

View file

@ -33,6 +33,11 @@ extern crate tracing;
#[macro_use]
extern crate rustc_middle;
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_macros::fluent_messages;
mod errors;
pub mod infer;
pub mod traits;
fluent_messages! { "../locales/en-US.ftl" }