@@ -276,6 +276,18 @@ pub enum SubdiagnosticMessage {
276
276
/// Non-translatable diagnostic message.
277
277
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
278
278
Str ( String ) ,
279
+ /// Translatable message which has already been translated eagerly.
280
+ ///
281
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
282
+ /// be instantiated multiple times with different values. As translation normally happens
283
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
284
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
285
+ /// values and only the final value will be set when translation occurs - resulting in
286
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
287
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
288
+ /// stores messages which have been translated eagerly.
289
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
290
+ Eager ( String ) ,
279
291
/// Identifier of a Fluent message. Instances of this variant are generated by the
280
292
/// `Subdiagnostic` derive.
281
293
FluentIdentifier ( FluentId ) ,
@@ -303,8 +315,20 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
303
315
#[ rustc_diagnostic_item = "DiagnosticMessage" ]
304
316
pub enum DiagnosticMessage {
305
317
/// Non-translatable diagnostic message.
306
- // FIXME(davidtwco ): can a `Cow<'static, str>` be used here?
318
+ // FIXME(#100717 ): can a `Cow<'static, str>` be used here?
307
319
Str ( String ) ,
320
+ /// Translatable message which has already been translated eagerly.
321
+ ///
322
+ /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
323
+ /// be instantiated multiple times with different values. As translation normally happens
324
+ /// immediately prior to emission, after the diagnostic and subdiagnostic derive logic has run,
325
+ /// the setting of diagnostic arguments in the derived code will overwrite previous variable
326
+ /// values and only the final value will be set when translation occurs - resulting in
327
+ /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
328
+ /// happening immediately after the subdiagnostic derive's logic has been run. This variant
329
+ /// stores messages which have been translated eagerly.
330
+ // FIXME(#100717): can a `Cow<'static, str>` be used here?
331
+ Eager ( String ) ,
308
332
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
309
333
/// message.
310
334
///
@@ -323,6 +347,7 @@ impl DiagnosticMessage {
323
347
pub fn with_subdiagnostic_message ( & self , sub : SubdiagnosticMessage ) -> Self {
324
348
let attr = match sub {
325
349
SubdiagnosticMessage :: Str ( s) => return DiagnosticMessage :: Str ( s) ,
350
+ SubdiagnosticMessage :: Eager ( s) => return DiagnosticMessage :: Eager ( s) ,
326
351
SubdiagnosticMessage :: FluentIdentifier ( id) => {
327
352
return DiagnosticMessage :: FluentIdentifier ( id, None ) ;
328
353
}
@@ -331,6 +356,7 @@ impl DiagnosticMessage {
331
356
332
357
match self {
333
358
DiagnosticMessage :: Str ( s) => DiagnosticMessage :: Str ( s. clone ( ) ) ,
359
+ DiagnosticMessage :: Eager ( s) => DiagnosticMessage :: Eager ( s. clone ( ) ) ,
334
360
DiagnosticMessage :: FluentIdentifier ( id, _) => {
335
361
DiagnosticMessage :: FluentIdentifier ( id. clone ( ) , Some ( attr) )
336
362
}
@@ -379,6 +405,7 @@ impl Into<SubdiagnosticMessage> for DiagnosticMessage {
379
405
fn into ( self ) -> SubdiagnosticMessage {
380
406
match self {
381
407
DiagnosticMessage :: Str ( s) => SubdiagnosticMessage :: Str ( s) ,
408
+ DiagnosticMessage :: Eager ( s) => SubdiagnosticMessage :: Eager ( s) ,
382
409
DiagnosticMessage :: FluentIdentifier ( id, None ) => {
383
410
SubdiagnosticMessage :: FluentIdentifier ( id)
384
411
}
0 commit comments