diff options
| author | bors <bors@rust-lang.org> | 2024-03-05 02:58:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-05 02:58:34 +0000 |
| commit | 1547c076bfec8abb819d6a81e1e4095d267bd5b4 (patch) | |
| tree | cb13d4c597ac854933926f459bc4edc6ff7c9b5c /compiler/rustc_errors/src | |
| parent | 2eeff462b762ed00f9d557d8c6ad7a3d562f692a (diff) | |
| parent | 1cd957498bd4f42b69b87b4463ebde259d0a96c4 (diff) | |
| download | rust-1547c076bfec8abb819d6a81e1e4095d267bd5b4.tar.gz rust-1547c076bfec8abb819d6a81e1e4095d267bd5b4.zip | |
Auto merge of #121780 - nnethercote:diag-renaming2, r=davidtwco
Diagnostic renaming 2 A sequel to #121489. r? `@davidtwco`
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 87 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 84 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/tests.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/translation.rs | 14 |
7 files changed, 114 insertions, 117 deletions
diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index e6668769b95..b71b93cc67c 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -9,8 +9,8 @@ use crate::emitter::FileWithAnnotatedLines; use crate::snippet::Line; use crate::translation::{to_fluent_args, Translate}; use crate::{ - CodeSuggestion, DiagInner, DiagnosticMessage, Emitter, ErrCode, FluentBundle, - LazyFallbackBundle, Level, MultiSpan, Style, Subdiag, + CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, FluentBundle, LazyFallbackBundle, + Level, MultiSpan, Style, Subdiag, }; use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use rustc_data_structures::sync::Lrc; @@ -125,7 +125,7 @@ impl AnnotateSnippetEmitter { fn emit_messages_default( &mut self, level: &Level, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option<ErrCode>, msp: &MultiSpan, diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 1c820bfd01f..5390dda9b21 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -1,7 +1,7 @@ use crate::snippet::Style; use crate::{ - CodeSuggestion, DiagCtxt, DiagnosticMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, - MultiSpan, StashKey, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, + CodeSuggestion, DiagCtxt, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, MultiSpan, + StashKey, SubdiagMessage, Substitution, SubstitutionPart, SuggestionStyle, }; use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::fluent_value_from_str_list_sep_by_and; @@ -182,15 +182,14 @@ where /// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used /// (to optionally perform eager translation). - fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>( + fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( self, diag: &mut Diag<'_, G>, f: F, ); } -pub trait SubdiagnosticMessageOp<G> = - Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage; +pub trait SubdiagMessageOp<G> = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage; /// Trait implemented by lint types. This should not be implemented manually. Instead, use /// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic]. @@ -199,7 +198,7 @@ pub trait DecorateLint<'a, G: EmissionGuarantee> { /// Decorate and emit a lint. fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>); - fn msg(&self) -> DiagnosticMessage; + fn msg(&self) -> DiagMessage; } #[derive(Clone, Debug, Encodable, Decodable)] @@ -291,7 +290,7 @@ pub struct DiagInner { // outside of what methods in this crate themselves allow. pub(crate) level: Level, - pub messages: Vec<(DiagnosticMessage, Style)>, + pub messages: Vec<(DiagMessage, Style)>, pub code: Option<ErrCode>, pub span: MultiSpan, pub children: Vec<Subdiag>, @@ -312,12 +311,12 @@ pub struct DiagInner { impl DiagInner { #[track_caller] - pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self { + pub fn new<M: Into<DiagMessage>>(level: Level, message: M) -> Self { DiagInner::new_with_messages(level, vec![(message.into(), Style::NoStyle)]) } #[track_caller] - pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self { + pub fn new_with_messages(level: Level, messages: Vec<(DiagMessage, Style)>) -> Self { DiagInner { level, messages, @@ -396,8 +395,8 @@ impl DiagInner { // See comment on `Diag::subdiagnostic_message_to_diagnostic_message`. pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, - attr: impl Into<SubdiagnosticMessage>, - ) -> DiagnosticMessage { + attr: impl Into<SubdiagMessage>, + ) -> DiagMessage { let msg = self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages"); msg.with_subdiagnostic_message(attr.into()) @@ -406,7 +405,7 @@ impl DiagInner { pub(crate) fn sub( &mut self, level: Level, - message: impl Into<SubdiagnosticMessage>, + message: impl Into<SubdiagMessage>, span: MultiSpan, ) { let sub = Subdiag { @@ -429,7 +428,7 @@ impl DiagInner { &self, ) -> ( &Level, - &[(DiagnosticMessage, Style)], + &[(DiagMessage, Style)], &Option<ErrCode>, &MultiSpan, &[Subdiag], @@ -472,7 +471,7 @@ impl PartialEq for DiagInner { #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct Subdiag { pub level: Level, - pub messages: Vec<(DiagnosticMessage, Style)>, + pub messages: Vec<(DiagMessage, Style)>, pub span: MultiSpan, } @@ -578,7 +577,7 @@ macro_rules! with_fn { impl<'a, G: EmissionGuarantee> Diag<'a, G> { #[rustc_lint_diagnostics] #[track_caller] - pub fn new<M: Into<DiagnosticMessage>>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self { + pub fn new(dcx: &'a DiagCtxt, level: Level, message: impl Into<DiagMessage>) -> Self { Self::new_diagnostic(dcx, DiagInner::new(level, message)) } @@ -623,7 +622,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is /// primary. #[rustc_lint_diagnostics] - pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn span_label(&mut self, span: Span, label: impl Into<SubdiagMessage>) -> &mut Self { let msg = self.subdiagnostic_message_to_diagnostic_message(label); self.span.push_span_label(span, msg); self @@ -718,7 +717,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_note, /// Add a note attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn note(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn note(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self { self.sub(Level::Note, msg, MultiSpan::new()); self } } @@ -729,7 +728,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { } /// This is like [`Diag::note()`], but it's only printed once. - pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self { self.sub(Level::OnceNote, msg, MultiSpan::new()); self } @@ -741,7 +740,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_note( &mut self, sp: impl Into<MultiSpan>, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, ) -> &mut Self { self.sub(Level::Note, msg, sp.into()); self @@ -752,7 +751,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_note_once<S: Into<MultiSpan>>( &mut self, sp: S, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, ) -> &mut Self { self.sub(Level::OnceNote, msg, sp.into()); self @@ -761,7 +760,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_warn, /// Add a warning attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn warn(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn warn(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self { self.sub(Level::Warning, msg, MultiSpan::new()); self } } @@ -772,7 +771,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_warn<S: Into<MultiSpan>>( &mut self, sp: S, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, ) -> &mut Self { self.sub(Level::Warning, msg, sp.into()); self @@ -781,13 +780,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_help, /// Add a help message attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn help(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn help(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self { self.sub(Level::Help, msg, MultiSpan::new()); self } } /// This is like [`Diag::help()`], but it's only printed once. - pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self { + pub fn help_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self { self.sub(Level::OnceHelp, msg, MultiSpan::new()); self } @@ -804,7 +803,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_help<S: Into<MultiSpan>>( &mut self, sp: S, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, ) -> &mut Self { self.sub(Level::Help, msg, sp.into()); self @@ -841,7 +840,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// In other words, multiple changes need to be applied as part of this suggestion. pub fn multipart_suggestion( &mut self, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -857,7 +856,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// In other words, multiple changes need to be applied as part of this suggestion. pub fn multipart_suggestion_verbose( &mut self, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -872,7 +871,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`]. pub fn multipart_suggestion_with_style( &mut self, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, mut suggestion: Vec<(Span, String)>, applicability: Applicability, style: SuggestionStyle, @@ -914,7 +913,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// improve understandability. pub fn tool_only_multipart_suggestion( &mut self, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -947,7 +946,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -965,7 +964,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_with_style( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, style: SuggestionStyle, @@ -990,7 +989,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_verbose( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1010,7 +1009,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestions( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestions: impl IntoIterator<Item = String>, applicability: Applicability, ) -> &mut Self { @@ -1026,7 +1025,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestions_with_style( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestions: impl IntoIterator<Item = String>, applicability: Applicability, style: SuggestionStyle, @@ -1055,7 +1054,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// See also [`Diag::multipart_suggestion()`]. pub fn multipart_suggestions( &mut self, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestions: impl IntoIterator<Item = Vec<(Span, String)>>, applicability: Applicability, ) -> &mut Self { @@ -1102,7 +1101,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_short( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1125,7 +1124,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_hidden( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1148,7 +1147,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn tool_only_span_suggestion( &mut self, sp: Span, - msg: impl Into<SubdiagnosticMessage>, + msg: impl Into<SubdiagMessage>, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1203,7 +1202,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_primary_message, /// Add a primary message. - pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self { + pub fn primary_message(&mut self, msg: impl Into<DiagMessage>) -> &mut Self { self.messages[0] = (msg.into(), Style::NoStyle); self } } @@ -1219,13 +1218,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { self } } - /// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by + /// Helper function that takes a `SubdiagMessage` and returns a `DiagMessage` by /// combining it with the primary message of the diagnostic (if translatable, otherwise it just /// passes the user's string along). pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, - attr: impl Into<SubdiagnosticMessage>, - ) -> DiagnosticMessage { + attr: impl Into<SubdiagMessage>, + ) -> DiagMessage { self.deref().subdiagnostic_message_to_diagnostic_message(attr) } @@ -1233,7 +1232,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// public methods above. /// /// Used by `proc_macro_server` for implementing `server::Diagnostic`. - pub fn sub(&mut self, level: Level, message: impl Into<SubdiagnosticMessage>, span: MultiSpan) { + pub fn sub(&mut self, level: Level, message: impl Into<SubdiagMessage>, span: MultiSpan) { self.deref_mut().sub(level, message, span); } @@ -1338,7 +1337,7 @@ impl<G: EmissionGuarantee> Drop for Diag<'_, G> { Some(diag) if !panicking() => { self.dcx.emit_diagnostic(DiagInner::new( Level::Bug, - DiagnosticMessage::from("the following error was constructed but not emitted"), + DiagMessage::from("the following error was constructed but not emitted"), )); self.dcx.emit_diagnostic(*diag); panic!("error was constructed but not emitted"); diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 70c8d971868..839bd65e4a6 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -2,7 +2,7 @@ use crate::diagnostic::DiagLocation; use crate::{fluent_generated as fluent, AddToDiagnostic}; use crate::{ Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, ErrCode, IntoDiagnostic, IntoDiagnosticArg, - Level, SubdiagnosticMessageOp, + Level, SubdiagMessageOp, }; use rustc_ast as ast; use rustc_ast_pretty::pprust; @@ -298,7 +298,7 @@ pub struct SingleLabelManySpans { pub label: &'static str, } impl AddToDiagnostic for SingleLabelManySpans { - fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>( + fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 5637c05d04c..293d8f01e67 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -17,7 +17,7 @@ use crate::snippet::{ use crate::styled_buffer::StyledBuffer; use crate::translation::{to_fluent_args, Translate}; use crate::{ - diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagnosticMessage, ErrCode, + diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagMessage, ErrCode, FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight, SuggestionStyle, TerminalUrl, }; @@ -339,7 +339,7 @@ pub trait Emitter: Translate { children.push(Subdiag { level: Level::Note, - messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)], + messages: vec![(DiagMessage::from(msg), Style::NoStyle)], span: MultiSpan::new(), }); } @@ -543,12 +543,10 @@ pub struct SilentEmitter { pub fatal_note: String, } -pub fn silent_translate<'a>( - message: &'a DiagnosticMessage, -) -> Result<Cow<'_, str>, TranslateError<'_>> { +pub fn silent_translate<'a>(message: &'a DiagMessage) -> Result<Cow<'_, str>, TranslateError<'_>> { match message { - DiagnosticMessage::Str(msg) | DiagnosticMessage::Translated(msg) => Ok(Cow::Borrowed(msg)), - DiagnosticMessage::FluentIdentifier(identifier, _) => { + DiagMessage::Str(msg) | DiagMessage::Translated(msg) => Ok(Cow::Borrowed(msg)), + DiagMessage::FluentIdentifier(identifier, _) => { // Any value works here. Ok(identifier.clone()) } @@ -568,7 +566,7 @@ impl Translate for SilentEmitter { // subdiagnostics result in a call to this. fn translate_message<'a>( &'a self, - message: &'a DiagnosticMessage, + message: &'a DiagMessage, _: &'a FluentArgs<'_>, ) -> Result<Cow<'_, str>, TranslateError<'_>> { silent_translate(message) @@ -1216,7 +1214,7 @@ impl HumanEmitter { fn msgs_to_buffer( &self, buffer: &mut StyledBuffer, - msgs: &[(DiagnosticMessage, Style)], + msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, padding: usize, label: &str, @@ -1291,7 +1289,7 @@ impl HumanEmitter { fn emit_messages_default_inner( &mut self, msp: &MultiSpan, - msgs: &[(DiagnosticMessage, Style)], + msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option<ErrCode>, level: &Level, @@ -2060,7 +2058,7 @@ impl HumanEmitter { fn emit_messages_default( &mut self, level: &Level, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option<ErrCode>, span: &MultiSpan, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 6b1ccbc5f7c..0a6d66f52da 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -39,7 +39,7 @@ pub use codes::*; pub use diagnostic::{ AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, - StringPart, Subdiag, SubdiagnosticMessageOp, + StringPart, Subdiag, SubdiagMessageOp, }; pub use diagnostic_impls::{ DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, @@ -47,8 +47,8 @@ pub use diagnostic_impls::{ }; pub use emitter::ColorConfig; pub use rustc_error_messages::{ - fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle, - LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage, + fallback_fluent_bundle, fluent_bundle, DelayDm, DiagMessage, FluentBundle, LanguageIdentifier, + LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagMessage, }; pub use rustc_lint_defs::{pluralize, Applicability}; pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker}; @@ -154,7 +154,7 @@ pub struct CodeSuggestion { /// ] /// ``` pub substitutions: Vec<Substitution>, - pub msg: DiagnosticMessage, + pub msg: DiagMessage, /// Visual representation of this suggestion. pub style: SuggestionStyle, /// Whether or not the suggestion is approximate @@ -631,12 +631,12 @@ impl DiagCtxt { } } - /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. + /// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`. pub fn eagerly_translate<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, - ) -> SubdiagnosticMessage { + ) -> SubdiagMessage { let inner = self.inner.borrow(); inner.eagerly_translate(message, args) } @@ -644,7 +644,7 @@ impl DiagCtxt { /// Translate `message` eagerly with `args` to `String`. pub fn eagerly_translate_to_string<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, ) -> String { let inner = self.inner.borrow(); @@ -904,7 +904,7 @@ impl DiagCtxt { // configuration like `--cap-lints allow --force-warn bare_trait_objects`. inner.emit_diagnostic(DiagInner::new( ForceWarning(None), - DiagnosticMessage::Str(warnings), + DiagMessage::Str(warnings), )); } (_, 0) => { @@ -1078,13 +1078,13 @@ impl DiagCtxt { impl DiagCtxt { // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, BugAbort> { + pub fn struct_bug(&self, msg: impl Into<DiagMessage>) -> Diag<'_, BugAbort> { Diag::new(self, Bug, msg) } // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn bug(&self, msg: impl Into<DiagnosticMessage>) -> ! { + pub fn bug(&self, msg: impl Into<DiagMessage>) -> ! { self.struct_bug(msg).emit() } @@ -1093,14 +1093,14 @@ impl DiagCtxt { pub fn struct_span_bug( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> Diag<'_, BugAbort> { self.struct_bug(msg).with_span(span) } // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! { + pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) -> ! { self.struct_span_bug(span, msg).emit() } @@ -1116,13 +1116,13 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, FatalAbort> { + pub fn struct_fatal(&self, msg: impl Into<DiagMessage>) -> Diag<'_, FatalAbort> { Diag::new(self, Fatal, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! { + pub fn fatal(&self, msg: impl Into<DiagMessage>) -> ! { self.struct_fatal(msg).emit() } @@ -1131,14 +1131,14 @@ impl DiagCtxt { pub fn struct_span_fatal( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> Diag<'_, FatalAbort> { self.struct_fatal(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! { + pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) -> ! { self.struct_span_fatal(span, msg).emit() } @@ -1174,13 +1174,13 @@ impl DiagCtxt { // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_> { + pub fn struct_err(&self, msg: impl Into<DiagMessage>) -> Diag<'_> { Diag::new(self, Error, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed { + pub fn err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed { self.struct_err(msg).emit() } @@ -1189,7 +1189,7 @@ impl DiagCtxt { pub fn struct_span_err( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> Diag<'_> { self.struct_err(msg).with_span(span) } @@ -1199,7 +1199,7 @@ impl DiagCtxt { pub fn span_err( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> ErrorGuaranteed { self.struct_span_err(span, msg).emit() } @@ -1217,7 +1217,7 @@ impl DiagCtxt { /// Ensures that an error is printed. See `Level::DelayedBug`. // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed { + pub fn delayed_bug(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed { Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit() } @@ -1230,20 +1230,20 @@ impl DiagCtxt { pub fn span_delayed_bug( &self, sp: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> ErrorGuaranteed { Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit() } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> { + pub fn struct_warn(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> { Diag::new(self, Warning, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn warn(&self, msg: impl Into<DiagnosticMessage>) { + pub fn warn(&self, msg: impl Into<DiagMessage>) { self.struct_warn(msg).emit() } @@ -1252,14 +1252,14 @@ impl DiagCtxt { pub fn struct_span_warn( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> Diag<'_, ()> { self.struct_warn(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) { + pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) { self.struct_span_warn(span, msg).emit() } @@ -1275,13 +1275,13 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> { + pub fn struct_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> { Diag::new(self, Note, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn note(&self, msg: impl Into<DiagnosticMessage>) { + pub fn note(&self, msg: impl Into<DiagMessage>) { self.struct_note(msg).emit() } @@ -1290,14 +1290,14 @@ impl DiagCtxt { pub fn struct_span_note( &self, span: impl Into<MultiSpan>, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) -> Diag<'_, ()> { self.struct_note(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) { + pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagMessage>) { self.struct_span_note(span, msg).emit() } @@ -1313,19 +1313,19 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> { + pub fn struct_help(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> { Diag::new(self, Help, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_failure_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> { + pub fn struct_failure_note(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> { Diag::new(self, FailureNote, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> { + pub fn struct_allow(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> { Diag::new(self, Allow, msg) } @@ -1333,7 +1333,7 @@ impl DiagCtxt { #[track_caller] pub fn struct_expect( &self, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, id: LintExpectationId, ) -> Diag<'_, ()> { Diag::new(self, Expect(id), msg) @@ -1553,19 +1553,19 @@ impl DiagCtxtInner { self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied()) } - /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. + /// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`. pub fn eagerly_translate<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, - ) -> SubdiagnosticMessage { - SubdiagnosticMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) + ) -> SubdiagMessage { + SubdiagMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) } /// Translate `message` eagerly with `args` to `String`. pub fn eagerly_translate_to_string<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator<Item = DiagArg<'a>>, ) -> String { let args = crate::translation::to_fluent_args(args); @@ -1575,8 +1575,8 @@ impl DiagCtxtInner { fn eagerly_translate_for_subdiag( &self, diag: &DiagInner, - msg: impl Into<SubdiagnosticMessage>, - ) -> SubdiagnosticMessage { + msg: impl Into<SubdiagMessage>, + ) -> SubdiagMessage { let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); self.eagerly_translate(msg, diag.args.iter()) } diff --git a/compiler/rustc_errors/src/tests.rs b/compiler/rustc_errors/src/tests.rs index 79a2af7f38f..50d58aec36a 100644 --- a/compiler/rustc_errors/src/tests.rs +++ b/compiler/rustc_errors/src/tests.rs @@ -5,7 +5,7 @@ use crate::FluentBundle; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError}; use rustc_error_messages::langid; -use rustc_error_messages::DiagnosticMessage; +use rustc_error_messages::DiagMessage; struct Dummy { bundle: FluentBundle, @@ -53,7 +53,7 @@ fn wellformed_fluent() { args.set("name", "Foo"); args.set("ty", "std::string::String"); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("suggestion".into()), ); @@ -65,7 +65,7 @@ fn wellformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("value_borrowed_label".into()), ); @@ -77,7 +77,7 @@ fn wellformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("occurs_because_label".into()), ); @@ -88,7 +88,7 @@ fn wellformed_fluent() { ); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("label".into()), ); @@ -112,7 +112,7 @@ fn misformed_fluent() { args.set("name", "Foo"); args.set("ty", "std::string::String"); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("value_borrowed_label".into()), ); @@ -141,7 +141,7 @@ fn misformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("label".into()), ); @@ -168,7 +168,7 @@ fn misformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("occurs_because_label".into()), ); diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index 1f98ba4c3b9..bf0026568ce 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -1,6 +1,6 @@ use crate::error::{TranslateError, TranslateErrorKind}; use crate::snippet::Style; -use crate::{DiagArg, DiagnosticMessage, FluentBundle}; +use crate::{DiagArg, DiagMessage, FluentBundle}; use rustc_data_structures::sync::Lrc; pub use rustc_error_messages::FluentArgs; use std::borrow::Cow; @@ -37,10 +37,10 @@ pub trait Translate { /// unavailable for the requested locale. fn fallback_fluent_bundle(&self) -> &FluentBundle; - /// Convert `DiagnosticMessage`s to a string, performing translation if necessary. + /// Convert `DiagMessage`s to a string, performing translation if necessary. fn translate_messages( &self, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, ) -> Cow<'_, str> { Cow::Owned( @@ -51,18 +51,18 @@ pub trait Translate { ) } - /// Convert a `DiagnosticMessage` to a string, performing translation if necessary. + /// Convert a `DiagMessage` to a string, performing translation if necessary. fn translate_message<'a>( &'a self, - message: &'a DiagnosticMessage, + message: &'a DiagMessage, args: &'a FluentArgs<'_>, ) -> Result<Cow<'_, str>, TranslateError<'_>> { trace!(?message, ?args); let (identifier, attr) = match message { - DiagnosticMessage::Str(msg) | DiagnosticMessage::Translated(msg) => { + DiagMessage::Str(msg) | DiagMessage::Translated(msg) => { return Ok(Cow::Borrowed(msg)); } - DiagnosticMessage::FluentIdentifier(identifier, attr) => (identifier, attr), + DiagMessage::FluentIdentifier(identifier, attr) => (identifier, attr), }; let translate_with_bundle = |bundle: &'a FluentBundle| -> Result<Cow<'_, str>, TranslateError<'_>> { |
