Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,38 +230,6 @@ pub fn fallback_fluent_bundle(
})))
}

/// Abstraction over a message in a subdiagnostic (i.e. label, note, help, etc) to support both
/// translatable and non-translatable diagnostic messages.
///
/// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent
/// message so messages of this type must be combined with a `DiagMessage` (using
/// `DiagMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
#[rustc_diagnostic_item = "SubdiagMessage"]
pub enum SubdiagMessage {
/// Non-translatable diagnostic message.
Str(Cow<'static, str>),
/// An inline Fluent message. Instances of this variant are generated by the
/// `Subdiagnostic` derive.
Inline(Cow<'static, str>),
}

impl From<String> for SubdiagMessage {
fn from(s: String) -> Self {
SubdiagMessage::Str(Cow::Owned(s))
}
}
impl From<&'static str> for SubdiagMessage {
fn from(s: &'static str) -> Self {
SubdiagMessage::Str(Cow::Borrowed(s))
}
}
impl From<Cow<'static, str>> for SubdiagMessage {
fn from(s: Cow<'static, str>) -> Self {
SubdiagMessage::Str(s)
}
}

/// Abstraction over a message in a diagnostic to support both translatable and non-translatable
/// diagnostic messages.
///
Expand All @@ -281,18 +249,6 @@ pub enum DiagMessage {
}

impl DiagMessage {
/// Given a `SubdiagMessage` which may contain a Fluent attribute, create a new
/// `DiagMessage` that combines that attribute with the Fluent identifier of `self`.
///
/// - If the `SubdiagMessage` is non-translatable then return the message as a `DiagMessage`.
/// - If `self` is non-translatable then return `self`'s message.
pub fn with_subdiagnostic_message(&self, sub: SubdiagMessage) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the heart of the change, right? I.e. this was the main thing that distinguished DiagMessage and SubdiagMessage... I assume the .ftl removal eliminated uses of this method?

Copy link
Contributor Author

@JonathanBrouwer JonathanBrouwer Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, previously sub-diags like #[help] were allowed to have no slug, and would automatically take the parent DiagMessage's slug and add _help. There was an extra variant for this in SubdiagMessage which was already removed.

After the removal of .ftl files, all sub-diags need to have their own message so this distinction no longer exists

match sub {
SubdiagMessage::Str(s) => DiagMessage::Str(s),
SubdiagMessage::Inline(s) => DiagMessage::Inline(s),
}
}

pub fn as_str(&self) -> Option<&str> {
match self {
DiagMessage::Str(s) => Some(s),
Expand All @@ -317,20 +273,6 @@ impl From<Cow<'static, str>> for DiagMessage {
}
}

/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but
/// 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
/// 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.
impl From<DiagMessage> for SubdiagMessage {
fn from(val: DiagMessage) -> Self {
match val {
DiagMessage::Str(s) => SubdiagMessage::Str(s),
DiagMessage::Inline(s) => SubdiagMessage::Inline(s),
}
}
}

/// A span together with some additional data.
#[derive(Clone, Debug)]
pub struct SpanLabel {
Expand Down
Loading
Loading