attr => "../locales/en-US/attr.ftl",
borrowck => "../locales/en-US/borrowck.ftl",
builtin_macros => "../locales/en-US/builtin_macros.ftl",
+ compiletest => "../locales/en-US/compiletest.ftl",
const_eval => "../locales/en-US/const_eval.ftl",
codegen_gcc => "../locales/en-US/codegen_gcc.ftl",
driver => "../locales/en-US/driver.ftl",
expand => "../locales/en-US/expand.ftl",
- session => "../locales/en-US/session.ftl",
- interface => "../locales/en-US/interface.ftl",
+ hir_analysis => "../locales/en-US/hir_analysis.ftl",
infer => "../locales/en-US/infer.ftl",
+ interface => "../locales/en-US/interface.ftl",
lint => "../locales/en-US/lint.ftl",
+ metadata => "../locales/en-US/metadata.ftl",
middle => "../locales/en-US/middle.ftl",
+ mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
monomorphize => "../locales/en-US/monomorphize.ftl",
- metadata => "../locales/en-US/metadata.ftl",
parser => "../locales/en-US/parser.ftl",
passes => "../locales/en-US/passes.ftl",
plugin_impl => "../locales/en-US/plugin_impl.ftl",
privacy => "../locales/en-US/privacy.ftl",
query_system => "../locales/en-US/query_system.ftl",
- trait_selection => "../locales/en-US/trait_selection.ftl",
save_analysis => "../locales/en-US/save_analysis.ftl",
- ty_utils => "../locales/en-US/ty_utils.ftl",
- typeck => "../locales/en-US/typeck.ftl",
- mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
+ session => "../locales/en-US/session.ftl",
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
+ trait_selection => "../locales/en-US/trait_selection.ftl",
+ ty_utils => "../locales/en-US/ty_utils.ftl",
}
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
/// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
Str(String),
+ /// Translatable message which has already been translated eagerly.
+ ///
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
+ /// be instantiated multiple times with different values. As translation normally happens
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
+ /// values and only the final value will be set when translation occurs - resulting in
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
+ /// stores messages which have been translated eagerly.
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
+ Eager(String),
/// Identifier of a Fluent message. Instances of this variant are generated by the
/// `Subdiagnostic` derive.
FluentIdentifier(FluentId),
#[rustc_diagnostic_item = "DiagnosticMessage"]
pub enum DiagnosticMessage {
/// Non-translatable diagnostic message.
- // FIXME(davidtwco): can a `Cow<'static, str>` be used here?
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
Str(String),
+ /// Translatable message which has already been translated eagerly.
+ ///
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
+ /// be instantiated multiple times with different values. As translation normally happens
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
+ /// values and only the final value will be set when translation occurs - resulting in
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
+ /// stores messages which have been translated eagerly.
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
+ Eager(String),
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
/// message.
///
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
let attr = match sub {
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
+ SubdiagnosticMessage::Eager(s) => return DiagnosticMessage::Eager(s),
SubdiagnosticMessage::FluentIdentifier(id) => {
return DiagnosticMessage::FluentIdentifier(id, None);
}
match self {
DiagnosticMessage::Str(s) => DiagnosticMessage::Str(s.clone()),
+ DiagnosticMessage::Eager(s) => DiagnosticMessage::Eager(s.clone()),
DiagnosticMessage::FluentIdentifier(id, _) => {
DiagnosticMessage::FluentIdentifier(id.clone(), Some(attr))
}
}
}
+/// A workaround for "good path" ICEs when formatting types in disables lints.
+///
+/// Delays formatting until `.into(): DiagnosticMessage` is used.
+pub struct DelayDm<F>(pub F);
+
+impl<F: FnOnce() -> String> From<DelayDm<F>> for DiagnosticMessage {
+ fn from(DelayDm(f): DelayDm<F>) -> Self {
+ DiagnosticMessage::from(f())
+ }
+}
+
/// 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
fn into(self) -> SubdiagnosticMessage {
match self {
DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s),
+ DiagnosticMessage::Eager(s) => SubdiagnosticMessage::Eager(s),
DiagnosticMessage::FluentIdentifier(id, None) => {
SubdiagnosticMessage::FluentIdentifier(id)
}