@@ -35,6 +35,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
35
35
36
36
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
37
37
fluent_messages ! {
38
+ // tidy-alphabetical-start
38
39
ast_lowering => "../locales/en-US/ast_lowering.ftl" ,
39
40
ast_passes => "../locales/en-US/ast_passes.ftl" ,
40
41
attr => "../locales/en-US/attr.ftl" ,
@@ -64,6 +65,7 @@ fluent_messages! {
64
65
symbol_mangling => "../locales/en-US/symbol_mangling.ftl" ,
65
66
trait_selection => "../locales/en-US/trait_selection.ftl" ,
66
67
ty_utils => "../locales/en-US/ty_utils.ftl" ,
68
+ // tidy-alphabetical-end
67
69
}
68
70
69
71
pub use fluent_generated:: { self as fluent, DEFAULT_LOCALE_RESOURCES } ;
@@ -277,6 +279,18 @@ pub enum SubdiagnosticMessage {
277
279
/// Non-translatable diagnostic message.
278
280
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
279
281
Str ( String ) ,
282
+ /// Translatable message which has already been translated eagerly.
283
+ ///
284
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
285
+ /// be instantiated multiple times with different values. As translation normally happens
286
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
287
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
288
+ /// values and only the final value will be set when translation occurs - resulting in
289
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
290
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
291
+ /// stores messages which have been translated eagerly.
292
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
293
+ Eager ( String ) ,
280
294
/// Identifier of a Fluent message. Instances of this variant are generated by the
281
295
/// `Subdiagnostic` derive.
282
296
FluentIdentifier ( FluentId ) ,
@@ -304,8 +318,20 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
304
318
#[ rustc_diagnostic_item = "DiagnosticMessage" ]
305
319
pub enum DiagnosticMessage {
306
320
/// Non-translatable diagnostic message.
307
- // FIXME(davidtwco ): can a `Cow<'static, str>` be used here?
321
+ // FIXME(#100717 ): can a `Cow<'static, str>` be used here?
308
322
Str ( String ) ,
323
+ /// Translatable message which has already been translated eagerly.
324
+ ///
325
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
326
+ /// be instantiated multiple times with different values. As translation normally happens
327
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
328
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
329
+ /// values and only the final value will be set when translation occurs - resulting in
330
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
331
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
332
+ /// stores messages which have been translated eagerly.
333
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
334
+ Eager ( String ) ,
309
335
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
310
336
/// message.
311
337
///
@@ -324,6 +350,7 @@ impl DiagnosticMessage {
324
350
pub fn with_subdiagnostic_message ( & self , sub : SubdiagnosticMessage ) -> Self {
325
351
let attr = match sub {
326
352
SubdiagnosticMessage :: Str ( s) => return DiagnosticMessage :: Str ( s) ,
353
+ SubdiagnosticMessage :: Eager ( s) => return DiagnosticMessage :: Eager ( s) ,
327
354
SubdiagnosticMessage :: FluentIdentifier ( id) => {
328
355
return DiagnosticMessage :: FluentIdentifier ( id, None ) ;
329
356
}
@@ -332,6 +359,7 @@ impl DiagnosticMessage {
332
359
333
360
match self {
334
361
DiagnosticMessage :: Str ( s) => DiagnosticMessage :: Str ( s. clone ( ) ) ,
362
+ DiagnosticMessage :: Eager ( s) => DiagnosticMessage :: Eager ( s. clone ( ) ) ,
335
363
DiagnosticMessage :: FluentIdentifier ( id, _) => {
336
364
DiagnosticMessage :: FluentIdentifier ( id. clone ( ) , Some ( attr) )
337
365
}
@@ -367,6 +395,7 @@ impl Into<SubdiagnosticMessage> for DiagnosticMessage {
367
395
fn into ( self ) -> SubdiagnosticMessage {
368
396
match self {
369
397
DiagnosticMessage :: Str ( s) => SubdiagnosticMessage :: Str ( s) ,
398
+ DiagnosticMessage :: Eager ( s) => SubdiagnosticMessage :: Eager ( s) ,
370
399
DiagnosticMessage :: FluentIdentifier ( id, None ) => {
371
400
SubdiagnosticMessage :: FluentIdentifier ( id)
372
401
}
0 commit comments