@@ -276,6 +276,18 @@ pub enum SubdiagnosticMessage {
276276 /// Non-translatable diagnostic message.
277277 // FIXME(davidtwco): can a `Cow<'static, str>` be used here?
278278 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 ) ,
279291 /// Identifier of a Fluent message. Instances of this variant are generated by the
280292 /// `Subdiagnostic` derive.
281293 FluentIdentifier ( FluentId ) ,
@@ -303,8 +315,20 @@ impl<S: Into<String>> From<S> for SubdiagnosticMessage {
303315#[ rustc_diagnostic_item = "DiagnosticMessage" ]
304316pub enum DiagnosticMessage {
305317 /// 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?
307319 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 ) ,
308332 /// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
309333 /// message.
310334 ///
@@ -323,6 +347,7 @@ impl DiagnosticMessage {
323347 pub fn with_subdiagnostic_message ( & self , sub : SubdiagnosticMessage ) -> Self {
324348 let attr = match sub {
325349 SubdiagnosticMessage :: Str ( s) => return DiagnosticMessage :: Str ( s) ,
350+ SubdiagnosticMessage :: Eager ( s) => return DiagnosticMessage :: Eager ( s) ,
326351 SubdiagnosticMessage :: FluentIdentifier ( id) => {
327352 return DiagnosticMessage :: FluentIdentifier ( id, None ) ;
328353 }
@@ -331,6 +356,7 @@ impl DiagnosticMessage {
331356
332357 match self {
333358 DiagnosticMessage :: Str ( s) => DiagnosticMessage :: Str ( s. clone ( ) ) ,
359+ DiagnosticMessage :: Eager ( s) => DiagnosticMessage :: Eager ( s. clone ( ) ) ,
334360 DiagnosticMessage :: FluentIdentifier ( id, _) => {
335361 DiagnosticMessage :: FluentIdentifier ( id. clone ( ) , Some ( attr) )
336362 }
@@ -379,6 +405,7 @@ impl Into<SubdiagnosticMessage> for DiagnosticMessage {
379405 fn into ( self ) -> SubdiagnosticMessage {
380406 match self {
381407 DiagnosticMessage :: Str ( s) => SubdiagnosticMessage :: Str ( s) ,
408+ DiagnosticMessage :: Eager ( s) => SubdiagnosticMessage :: Eager ( s) ,
382409 DiagnosticMessage :: FluentIdentifier ( id, None ) => {
383410 SubdiagnosticMessage :: FluentIdentifier ( id)
384411 }
0 commit comments