Remove SubdiagMessage in favour of the identical DiagMessage
This commit is contained in:
parent
71dc761bfe
commit
ea361287be
10 changed files with 56 additions and 162 deletions
|
|
@ -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.
|
||||
///
|
||||
|
|
@ -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 {
|
||||
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),
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue