Rename SubdiagnosticMessage as SubdiagMessage.

This commit is contained in:
Nicholas Nethercote 2024-02-29 14:53:44 +11:00
parent f16a8d0390
commit 60ea6e2831
12 changed files with 83 additions and 85 deletions

View File

@ -256,8 +256,8 @@ type FluentId = Cow<'static, str>;
/// message so messages of this type must be combined with a `DiagMessage` (using /// message so messages of this type must be combined with a `DiagMessage` (using
/// `DiagMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from /// `DiagMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
/// the `Subdiagnostic` derive refer to Fluent identifiers directly. /// the `Subdiagnostic` derive refer to Fluent identifiers directly.
#[rustc_diagnostic_item = "SubdiagnosticMessage"] #[rustc_diagnostic_item = "SubdiagMessage"]
pub enum SubdiagnosticMessage { pub enum SubdiagMessage {
/// Non-translatable diagnostic message. /// Non-translatable diagnostic message.
Str(Cow<'static, str>), Str(Cow<'static, str>),
/// Translatable message which has already been translated eagerly. /// Translatable message which has already been translated eagerly.
@ -278,19 +278,19 @@ pub enum SubdiagnosticMessage {
FluentAttr(FluentId), FluentAttr(FluentId),
} }
impl From<String> for SubdiagnosticMessage { impl From<String> for SubdiagMessage {
fn from(s: String) -> Self { fn from(s: String) -> Self {
SubdiagnosticMessage::Str(Cow::Owned(s)) SubdiagMessage::Str(Cow::Owned(s))
} }
} }
impl From<&'static str> for SubdiagnosticMessage { impl From<&'static str> for SubdiagMessage {
fn from(s: &'static str) -> Self { fn from(s: &'static str) -> Self {
SubdiagnosticMessage::Str(Cow::Borrowed(s)) SubdiagMessage::Str(Cow::Borrowed(s))
} }
} }
impl From<Cow<'static, str>> for SubdiagnosticMessage { impl From<Cow<'static, str>> for SubdiagMessage {
fn from(s: Cow<'static, str>) -> Self { fn from(s: Cow<'static, str>) -> Self {
SubdiagnosticMessage::Str(s) SubdiagMessage::Str(s)
} }
} }
@ -319,20 +319,19 @@ pub enum DiagMessage {
} }
impl DiagMessage { impl DiagMessage {
/// Given a `SubdiagnosticMessage` which may contain a Fluent attribute, create a new /// Given a `SubdiagMessage` which may contain a Fluent attribute, create a new
/// `DiagMessage` that combines that attribute with the Fluent identifier of `self`. /// `DiagMessage` that combines that attribute with the Fluent identifier of `self`.
/// ///
/// - If the `SubdiagnosticMessage` is non-translatable then return the message as a /// - If the `SubdiagMessage` is non-translatable then return the message as a `DiagMessage`.
/// `DiagMessage`.
/// - If `self` is non-translatable then return `self`'s message. /// - If `self` is non-translatable then return `self`'s message.
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self { pub fn with_subdiagnostic_message(&self, sub: SubdiagMessage) -> Self {
let attr = match sub { let attr = match sub {
SubdiagnosticMessage::Str(s) => return DiagMessage::Str(s), SubdiagMessage::Str(s) => return DiagMessage::Str(s),
SubdiagnosticMessage::Translated(s) => return DiagMessage::Translated(s), SubdiagMessage::Translated(s) => return DiagMessage::Translated(s),
SubdiagnosticMessage::FluentIdentifier(id) => { SubdiagMessage::FluentIdentifier(id) => {
return DiagMessage::FluentIdentifier(id, None); return DiagMessage::FluentIdentifier(id, None);
} }
SubdiagnosticMessage::FluentAttr(attr) => attr, SubdiagMessage::FluentAttr(attr) => attr,
}; };
match self { match self {
@ -380,19 +379,19 @@ impl<F: FnOnce() -> String> From<DelayDm<F>> for DiagMessage {
} }
/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but /// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but
/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagnosticMessage` and the /// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagMessage` and the
/// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be /// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be
/// able to convert between these, as much as they'll be converted back into `DiagMessage` /// able to convert between these, as much as they'll be converted back into `DiagMessage`
/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive. /// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
impl Into<SubdiagnosticMessage> for DiagMessage { impl Into<SubdiagMessage> for DiagMessage {
fn into(self) -> SubdiagnosticMessage { fn into(self) -> SubdiagMessage {
match self { match self {
DiagMessage::Str(s) => SubdiagnosticMessage::Str(s), DiagMessage::Str(s) => SubdiagMessage::Str(s),
DiagMessage::Translated(s) => SubdiagnosticMessage::Translated(s), DiagMessage::Translated(s) => SubdiagMessage::Translated(s),
DiagMessage::FluentIdentifier(id, None) => SubdiagnosticMessage::FluentIdentifier(id), DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id),
// There isn't really a sensible behaviour for this because it loses information but // There isn't really a sensible behaviour for this because it loses information but
// this is the most sensible of the behaviours. // this is the most sensible of the behaviours.
DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagnosticMessage::FluentAttr(attr), DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagMessage::FluentAttr(attr),
} }
} }
} }

View File

@ -1,7 +1,7 @@
use crate::snippet::Style; use crate::snippet::Style;
use crate::{ use crate::{
CodeSuggestion, DiagCtxt, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, MultiSpan, CodeSuggestion, DiagCtxt, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, MultiSpan,
StashKey, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, StashKey, SubdiagMessage, Substitution, SubstitutionPart, SuggestionStyle,
}; };
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_error_messages::fluent_value_from_str_list_sep_by_and; use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@ -189,8 +189,7 @@ where
); );
} }
pub trait SubdiagnosticMessageOp<G> = pub trait SubdiagnosticMessageOp<G> = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage;
Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
/// Trait implemented by lint types. This should not be implemented manually. Instead, use /// Trait implemented by lint types. This should not be implemented manually. Instead, use
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic]. /// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
@ -396,7 +395,7 @@ impl DiagInner {
// See comment on `Diag::subdiagnostic_message_to_diagnostic_message`. // See comment on `Diag::subdiagnostic_message_to_diagnostic_message`.
pub(crate) fn subdiagnostic_message_to_diagnostic_message( pub(crate) fn subdiagnostic_message_to_diagnostic_message(
&self, &self,
attr: impl Into<SubdiagnosticMessage>, attr: impl Into<SubdiagMessage>,
) -> DiagMessage { ) -> DiagMessage {
let msg = let msg =
self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages"); self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages");
@ -406,7 +405,7 @@ impl DiagInner {
pub(crate) fn sub( pub(crate) fn sub(
&mut self, &mut self,
level: Level, level: Level,
message: impl Into<SubdiagnosticMessage>, message: impl Into<SubdiagMessage>,
span: MultiSpan, span: MultiSpan,
) { ) {
let sub = Subdiag { let sub = Subdiag {
@ -623,7 +622,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
/// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is /// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is
/// primary. /// primary.
#[rustc_lint_diagnostics] #[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); let msg = self.subdiagnostic_message_to_diagnostic_message(label);
self.span.push_span_label(span, msg); self.span.push_span_label(span, msg);
self self
@ -718,7 +717,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
with_fn! { with_note, with_fn! { with_note,
/// Add a note attached to this diagnostic. /// Add a note attached to this diagnostic.
#[rustc_lint_diagnostics] #[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.sub(Level::Note, msg, MultiSpan::new());
self self
} } } }
@ -729,7 +728,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
} }
/// This is like [`Diag::note()`], but it's only printed once. /// 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.sub(Level::OnceNote, msg, MultiSpan::new());
self self
} }
@ -741,7 +740,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_note( pub fn span_note(
&mut self, &mut self,
sp: impl Into<MultiSpan>, sp: impl Into<MultiSpan>,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
) -> &mut Self { ) -> &mut Self {
self.sub(Level::Note, msg, sp.into()); self.sub(Level::Note, msg, sp.into());
self self
@ -752,7 +751,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_note_once<S: Into<MultiSpan>>( pub fn span_note_once<S: Into<MultiSpan>>(
&mut self, &mut self,
sp: S, sp: S,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
) -> &mut Self { ) -> &mut Self {
self.sub(Level::OnceNote, msg, sp.into()); self.sub(Level::OnceNote, msg, sp.into());
self self
@ -761,7 +760,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
with_fn! { with_warn, with_fn! { with_warn,
/// Add a warning attached to this diagnostic. /// Add a warning attached to this diagnostic.
#[rustc_lint_diagnostics] #[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.sub(Level::Warning, msg, MultiSpan::new());
self self
} } } }
@ -772,7 +771,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_warn<S: Into<MultiSpan>>( pub fn span_warn<S: Into<MultiSpan>>(
&mut self, &mut self,
sp: S, sp: S,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
) -> &mut Self { ) -> &mut Self {
self.sub(Level::Warning, msg, sp.into()); self.sub(Level::Warning, msg, sp.into());
self self
@ -781,13 +780,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
with_fn! { with_help, with_fn! { with_help,
/// Add a help message attached to this diagnostic. /// Add a help message attached to this diagnostic.
#[rustc_lint_diagnostics] #[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.sub(Level::Help, msg, MultiSpan::new());
self self
} } } }
/// This is like [`Diag::help()`], but it's only printed once. /// 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.sub(Level::OnceHelp, msg, MultiSpan::new());
self self
} }
@ -804,7 +803,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_help<S: Into<MultiSpan>>( pub fn span_help<S: Into<MultiSpan>>(
&mut self, &mut self,
sp: S, sp: S,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
) -> &mut Self { ) -> &mut Self {
self.sub(Level::Help, msg, sp.into()); self.sub(Level::Help, msg, sp.into());
self 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. /// In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestion( pub fn multipart_suggestion(
&mut self, &mut self,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: Vec<(Span, String)>, suggestion: Vec<(Span, String)>,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &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. /// In other words, multiple changes need to be applied as part of this suggestion.
pub fn multipart_suggestion_verbose( pub fn multipart_suggestion_verbose(
&mut self, &mut self,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: Vec<(Span, String)>, suggestion: Vec<(Span, String)>,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -872,7 +871,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`]. /// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
pub fn multipart_suggestion_with_style( pub fn multipart_suggestion_with_style(
&mut self, &mut self,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
mut suggestion: Vec<(Span, String)>, mut suggestion: Vec<(Span, String)>,
applicability: Applicability, applicability: Applicability,
style: SuggestionStyle, style: SuggestionStyle,
@ -914,7 +913,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
/// improve understandability. /// improve understandability.
pub fn tool_only_multipart_suggestion( pub fn tool_only_multipart_suggestion(
&mut self, &mut self,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: Vec<(Span, String)>, suggestion: Vec<(Span, String)>,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -947,7 +946,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestion( pub fn span_suggestion(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -965,7 +964,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestion_with_style( pub fn span_suggestion_with_style(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
style: SuggestionStyle, style: SuggestionStyle,
@ -990,7 +989,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestion_verbose( pub fn span_suggestion_verbose(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1010,7 +1009,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestions( pub fn span_suggestions(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestions: impl IntoIterator<Item = String>, suggestions: impl IntoIterator<Item = String>,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1026,7 +1025,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestions_with_style( pub fn span_suggestions_with_style(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestions: impl IntoIterator<Item = String>, suggestions: impl IntoIterator<Item = String>,
applicability: Applicability, applicability: Applicability,
style: SuggestionStyle, style: SuggestionStyle,
@ -1055,7 +1054,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
/// See also [`Diag::multipart_suggestion()`]. /// See also [`Diag::multipart_suggestion()`].
pub fn multipart_suggestions( pub fn multipart_suggestions(
&mut self, &mut self,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>, suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1102,7 +1101,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestion_short( pub fn span_suggestion_short(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1125,7 +1124,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn span_suggestion_hidden( pub fn span_suggestion_hidden(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1148,7 +1147,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn tool_only_span_suggestion( pub fn tool_only_span_suggestion(
&mut self, &mut self,
sp: Span, sp: Span,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
suggestion: impl ToString, suggestion: impl ToString,
applicability: Applicability, applicability: Applicability,
) -> &mut Self { ) -> &mut Self {
@ -1219,12 +1218,12 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
self self
} } } }
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagMessage` 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 /// combining it with the primary message of the diagnostic (if translatable, otherwise it just
/// passes the user's string along). /// passes the user's string along).
pub(crate) fn subdiagnostic_message_to_diagnostic_message( pub(crate) fn subdiagnostic_message_to_diagnostic_message(
&self, &self,
attr: impl Into<SubdiagnosticMessage>, attr: impl Into<SubdiagMessage>,
) -> DiagMessage { ) -> DiagMessage {
self.deref().subdiagnostic_message_to_diagnostic_message(attr) self.deref().subdiagnostic_message_to_diagnostic_message(attr)
} }
@ -1233,7 +1232,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
/// public methods above. /// public methods above.
/// ///
/// Used by `proc_macro_server` for implementing `server::Diagnostic`. /// 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); self.deref_mut().sub(level, message, span);
} }

View File

@ -48,7 +48,7 @@ pub use diagnostic_impls::{
pub use emitter::ColorConfig; pub use emitter::ColorConfig;
pub use rustc_error_messages::{ pub use rustc_error_messages::{
fallback_fluent_bundle, fluent_bundle, DelayDm, DiagMessage, FluentBundle, LanguageIdentifier, fallback_fluent_bundle, fluent_bundle, DelayDm, DiagMessage, FluentBundle, LanguageIdentifier,
LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagMessage,
}; };
pub use rustc_lint_defs::{pluralize, Applicability}; pub use rustc_lint_defs::{pluralize, Applicability};
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker}; pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
@ -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>( pub fn eagerly_translate<'a>(
&self, &self,
message: DiagMessage, message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>, args: impl Iterator<Item = DiagArg<'a>>,
) -> SubdiagnosticMessage { ) -> SubdiagMessage {
let inner = self.inner.borrow(); let inner = self.inner.borrow();
inner.eagerly_translate(message, args) inner.eagerly_translate(message, args)
} }
@ -1553,13 +1553,13 @@ impl DiagCtxtInner {
self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied()) 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>( pub fn eagerly_translate<'a>(
&self, &self,
message: DiagMessage, message: DiagMessage,
args: impl Iterator<Item = DiagArg<'a>>, args: impl Iterator<Item = DiagArg<'a>>,
) -> SubdiagnosticMessage { ) -> SubdiagMessage {
SubdiagnosticMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) SubdiagMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args)))
} }
/// Translate `message` eagerly with `args` to `String`. /// Translate `message` eagerly with `args` to `String`.
@ -1575,8 +1575,8 @@ impl DiagCtxtInner {
fn eagerly_translate_for_subdiag( fn eagerly_translate_for_subdiag(
&self, &self,
diag: &DiagInner, diag: &DiagInner,
msg: impl Into<SubdiagnosticMessage>, msg: impl Into<SubdiagMessage>,
) -> SubdiagnosticMessage { ) -> SubdiagMessage {
let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); let msg = diag.subdiagnostic_message_to_diagnostic_message(msg);
self.eagerly_translate(msg, diag.args.iter()) self.eagerly_translate(msg, diag.args.iter())
} }

View File

@ -54,20 +54,20 @@ fn finish(body: TokenStream, resource: TokenStream) -> proc_macro::TokenStream {
/// identifiers for different subdiagnostic kinds. /// identifiers for different subdiagnostic kinds.
pub mod _subdiag { pub mod _subdiag {
/// Default for `#[help]` /// Default for `#[help]`
pub const help: rustc_errors::SubdiagnosticMessage = pub const help: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("help")); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
/// Default for `#[note]` /// Default for `#[note]`
pub const note: rustc_errors::SubdiagnosticMessage = pub const note: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("note")); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
/// Default for `#[warn]` /// Default for `#[warn]`
pub const warn: rustc_errors::SubdiagnosticMessage = pub const warn: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("warn")); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("warn"));
/// Default for `#[label]` /// Default for `#[label]`
pub const label: rustc_errors::SubdiagnosticMessage = pub const label: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("label")); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
/// Default for `#[suggestion]` /// Default for `#[suggestion]`
pub const suggestion: rustc_errors::SubdiagnosticMessage = pub const suggestion: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion")); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
} }
} }
} }
@ -275,8 +275,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
); );
constants.extend(quote! { constants.extend(quote! {
#[doc = #msg] #[doc = #msg]
pub const #snake_name: rustc_errors::SubdiagnosticMessage = pub const #snake_name: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed(#attr_name)); rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed(#attr_name));
}); });
} }

View File

@ -11,7 +11,7 @@ pub use self::suggest::SelfSource;
pub use self::MethodError::*; pub use self::MethodError::*;
use crate::FnCtxt; use crate::FnCtxt;
use rustc_errors::{Applicability, Diag, SubdiagnosticMessage}; use rustc_errors::{Applicability, Diag, SubdiagMessage};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def::{CtorOf, DefKind, Namespace};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn suggest_method_call( pub(crate) fn suggest_method_call(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
msg: impl Into<SubdiagnosticMessage> + std::fmt::Debug, msg: impl Into<SubdiagMessage> + std::fmt::Debug,
method_name: Ident, method_name: Ident,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
call_expr: &hir::Expr<'tcx>, call_expr: &hir::Expr<'tcx>,

View File

@ -403,7 +403,7 @@ impl LateLintPass<'_> for Diagnostics {
debug!(?ty); debug!(?ty);
if let Some(adt_def) = ty.ty_adt_def() if let Some(adt_def) = ty.ty_adt_def()
&& let Some(name) = cx.tcx.get_diagnostic_name(adt_def.did()) && let Some(name) = cx.tcx.get_diagnostic_name(adt_def.did())
&& matches!(name, sym::DiagMessage | sym::SubdiagnosticMessage) && matches!(name, sym::DiagMessage | sym::SubdiagMessage)
{ {
found_diagnostic_message = true; found_diagnostic_message = true;
break; break;

View File

@ -304,7 +304,7 @@ symbols! {
SpanCtxt, SpanCtxt,
String, String,
StructuralPartialEq, StructuralPartialEq,
SubdiagnosticMessage, SubdiagMessage,
Sync, Sync,
T, T,
Target, Target,

View File

@ -11,9 +11,9 @@ pub enum DiagMessage {
FluentIdentifier(std::borrow::Cow<'static, str>, Option<std::borrow::Cow<'static, str>>), FluentIdentifier(std::borrow::Cow<'static, str>, Option<std::borrow::Cow<'static, str>>),
} }
/// Copy of the relevant `SubdiagnosticMessage` variant constructed by `fluent_messages` as it /// Copy of the relevant `SubdiagMessage` variant constructed by `fluent_messages` as it
/// expects `crate::SubdiagnosticMessage` to exist. /// expects `crate::SubdiagMessage` to exist.
pub enum SubdiagnosticMessage { pub enum SubdiagMessage {
FluentAttr(std::borrow::Cow<'static, str>), FluentAttr(std::borrow::Cow<'static, str>),
} }

View File

@ -19,7 +19,7 @@ extern crate rustc_macros;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
use rustc_errors::{Applicability, DiagMessage, SubdiagnosticMessage}; use rustc_errors::{Applicability, DiagMessage, SubdiagMessage};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span; use rustc_span::Span;

View File

@ -25,7 +25,7 @@ extern crate rustc_middle;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
extern crate rustc_errors; extern crate rustc_errors;
use rustc_errors::{Applicability, DiagMessage, ErrCode, MultiSpan, SubdiagnosticMessage}; use rustc_errors::{Applicability, DiagMessage, ErrCode, MultiSpan, SubdiagMessage};
extern crate rustc_session; extern crate rustc_session;

View File

@ -10,7 +10,7 @@ extern crate rustc_fluent_macro;
extern crate rustc_macros; extern crate rustc_macros;
extern crate rustc_errors; extern crate rustc_errors;
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_errors::{DiagMessage, SubdiagnosticMessage}; use rustc_errors::{DiagMessage, SubdiagMessage};
extern crate rustc_session; extern crate rustc_session;
rustc_fluent_macro::fluent_messages! { "./example.ftl" } rustc_fluent_macro::fluent_messages! { "./example.ftl" }

View File

@ -17,7 +17,7 @@ extern crate rustc_macros;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
use rustc_errors::{Applicability, DiagMessage, SubdiagnosticMessage}; use rustc_errors::{Applicability, DiagMessage, SubdiagMessage};
use rustc_macros::Subdiagnostic; use rustc_macros::Subdiagnostic;
use rustc_span::Span; use rustc_span::Span;