@@ -181,22 +181,9 @@ where
181
181
Self : Sized ,
182
182
{
183
183
/// 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 > ) ;
195
185
}
196
186
197
- pub trait SubdiagMessageOp < G : EmissionGuarantee > =
198
- Fn ( & mut Diag <' _, G >, SubdiagMessage ) -> SubdiagMessage ;
199
-
200
187
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
201
188
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
202
189
#[ rustc_diagnostic_item = "LintDiagnostic" ]
@@ -1227,15 +1214,21 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
1227
1214
/// interpolated variables).
1228
1215
#[ rustc_lint_diagnostics]
1229
1216
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 ) ;
1236
1218
self
1237
1219
}
1238
1220
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
+
1239
1232
with_fn ! { with_span,
1240
1233
/// Add a span.
1241
1234
#[ rustc_lint_diagnostics]
0 commit comments