// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
fluent_messages! {
+ borrowck => "../locales/en-US/borrowck.ftl",
+ builtin_macros => "../locales/en-US/builtin_macros.ftl",
+ const_eval => "../locales/en-US/const_eval.ftl",
+ expand => "../locales/en-US/expand.ftl",
+ lint => "../locales/en-US/lint.ftl",
parser => "../locales/en-US/parser.ftl",
+ passes => "../locales/en-US/passes.ftl",
+ privacy => "../locales/en-US/privacy.ftl",
typeck => "../locales/en-US/typeck.ftl",
- builtin_macros => "../locales/en-US/builtin_macros.ftl",
}
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
FluentAttr(FluentId),
}
-impl SubdiagnosticMessage {
- /// Create a `SubdiagnosticMessage` for the provided Fluent attribute.
- pub fn attr(id: impl Into<FluentId>) -> Self {
- SubdiagnosticMessage::FluentAttr(id.into())
- }
-
- /// Create a `SubdiagnosticMessage` for the provided Fluent identifier.
- pub fn message(id: impl Into<FluentId>) -> Self {
- SubdiagnosticMessage::FluentIdentifier(id.into())
- }
-}
-
/// `From` impl that enables existing diagnostic calls to functions which now take
/// `impl Into<SubdiagnosticMessage>` to continue to work as before.
impl<S: Into<String>> From<S> for SubdiagnosticMessage {
/// - If `self` is non-translatable then return `self`'s message.
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
let attr = match sub {
- SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s.clone()),
+ SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
SubdiagnosticMessage::FluentIdentifier(id) => {
return DiagnosticMessage::FluentIdentifier(id, None);
}
_ => panic!("expected non-translatable diagnostic message"),
}
}
-
- /// Create a `DiagnosticMessage` for the provided Fluent identifier.
- pub fn new(id: impl Into<FluentId>) -> Self {
- DiagnosticMessage::FluentIdentifier(id.into(), None)
- }
}
/// `From` impl that enables existing diagnostic calls to functions which now take
}
}
+/// 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
+/// subdiagnostic derive refers to typed identifiers that are `DiagnosticMessage`s, so need to be
+/// able to convert between these, as much as they'll be converted back into `DiagnosticMessage`
+/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
+impl Into<SubdiagnosticMessage> for DiagnosticMessage {
+ fn into(self) -> SubdiagnosticMessage {
+ match self {
+ DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s),
+ DiagnosticMessage::FluentIdentifier(id, None) => {
+ SubdiagnosticMessage::FluentIdentifier(id)
+ }
+ // There isn't really a sensible behaviour for this because it loses information but
+ // this is the most sensible of the behaviours.
+ DiagnosticMessage::FluentIdentifier(_, Some(attr)) => {
+ SubdiagnosticMessage::FluentAttr(attr)
+ }
+ }
+ }
+}
+
/// A span together with some additional data.
#[derive(Clone, Debug)]
pub struct SpanLabel {