@@ -181,22 +181,9 @@ where
181181 Self : Sized ,
182182{
183183 /// Add a subdiagnostic to an existing diagnostic.
184- fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
185- self . add_to_diag_with ( diag, & |_, m| m) ;
186- }
187-
188- /// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used
189- /// (to optionally perform eager translation).
190- fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
191- self ,
192- diag : & mut Diag < ' _ , G > ,
193- f : & F ,
194- ) ;
184+ fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) ;
195185}
196186
197- pub trait SubdiagMessageOp < G : EmissionGuarantee > =
198- Fn ( & mut Diag <' _, G >, SubdiagMessage ) -> SubdiagMessage ;
199-
200187/// Trait implemented by lint types. This should not be implemented manually. Instead, use
201188/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
202189#[ rustc_diagnostic_item = "LintDiagnostic" ]
@@ -1227,15 +1214,21 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12271214 /// interpolated variables).
12281215 #[ rustc_lint_diagnostics]
12291216 pub fn subdiagnostic ( & mut self , subdiagnostic : impl Subdiagnostic ) -> & mut Self {
1230- let dcx = self . dcx ;
1231- subdiagnostic. add_to_diag_with ( self , & |diag, msg| {
1232- let args = diag. args . iter ( ) ;
1233- let msg = diag. subdiagnostic_message_to_diagnostic_message ( msg) ;
1234- dcx. eagerly_translate ( msg, args)
1235- } ) ;
1217+ subdiagnostic. add_to_diag ( self ) ;
12361218 self
12371219 }
12381220
1221+ /// Fluent variables are not namespaced from each other, so when
1222+ /// `Diagnostic`s and `Subdiagnostic`s use the same variable name,
1223+ /// one value will clobber the other. Eagerly translating the
1224+ /// diagnostic uses the variables defined right then, before the
1225+ /// clobbering occurs.
1226+ pub fn eagerly_translate ( & self , msg : impl Into < SubdiagMessage > ) -> SubdiagMessage {
1227+ let args = self . args . iter ( ) ;
1228+ let msg = self . subdiagnostic_message_to_diagnostic_message ( msg. into ( ) ) ;
1229+ self . dcx . eagerly_translate ( msg, args)
1230+ }
1231+
12391232 with_fn ! { with_span,
12401233 /// Add a span.
12411234 #[ rustc_lint_diagnostics]
0 commit comments