Skip to content

Commit de3e8ca

Browse files
committed
errors: set_arg takes IntoDiagnosticArg
Manual implementors of translatable diagnostics will need to call `set_arg`, not just the derive, so make this function a bit more ergonomic by taking `IntoDiagnosticArg` rather than `DiagnosticArgValue`. Signed-off-by: David Wood <[email protected]>
1 parent b5545f1 commit de3e8ca

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,9 @@ impl Diagnostic {
821821
pub fn set_arg(
822822
&mut self,
823823
name: impl Into<Cow<'static, str>>,
824-
arg: DiagnosticArgValue<'static>,
824+
arg: impl IntoDiagnosticArg,
825825
) -> &mut Self {
826-
self.args.push((name.into(), arg));
826+
self.args.push((name.into(), arg.into_diagnostic_arg()));
827827
self
828828
}
829829

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::diagnostic::DiagnosticArgValue;
1+
use crate::diagnostic::IntoDiagnosticArg;
22
use crate::{Diagnostic, DiagnosticId, DiagnosticMessage, DiagnosticStyledString, ErrorGuaranteed};
33
use crate::{Handler, Level, MultiSpan, StashKey};
44
use rustc_lint_defs::Applicability;
@@ -528,7 +528,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
528528
forward!(pub fn set_arg(
529529
&mut self,
530530
name: impl Into<Cow<'static, str>>,
531-
arg: DiagnosticArgValue<'static>,
531+
arg: impl IntoDiagnosticArg,
532532
) -> &mut Self);
533533

534534
forward!(pub fn subdiagnostic(

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
113113
quote! {
114114
#diag.set_arg(
115115
stringify!(#ident),
116-
#field_binding.into_diagnostic_arg()
116+
#field_binding
117117
);
118118
}
119119
} else {

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
349349
let generated = quote! {
350350
#diag.set_arg(
351351
stringify!(#ident),
352-
#binding.into_diagnostic_arg()
352+
#binding
353353
);
354354
};
355355

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ struct ErrorWithDefaultLabelAttr<'a> {
327327
}
328328

329329
#[derive(SessionDiagnostic)]
330-
//~^ ERROR no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
330+
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
331331
#[error(code = "E0123", slug = "foo")]
332332
struct ArgFieldWithoutSkip {
333333
#[primary_span]

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,26 @@ error: cannot find attribute `nonsense` in this scope
349349
LL | #[nonsense]
350350
| ^^^^^^^^
351351

352-
error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
352+
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
353353
--> $DIR/diagnostic-derive.rs:329:10
354354
|
355-
LL | struct Hello {}
356-
| ------------ method `into_diagnostic_arg` not found for this
357-
...
358355
LL | #[derive(SessionDiagnostic)]
359-
| ^^^^^^^^^^^^^^^^^ method not found in `Hello`
360-
|
356+
| ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
357+
|
358+
= help: the following other types implement trait `IntoDiagnosticArg`:
359+
&'a str
360+
Ident
361+
String
362+
Symbol
363+
rustc_middle::ty::Ty<'tcx>
364+
usize
365+
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
366+
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:531:19
367+
|
368+
LL | arg: impl IntoDiagnosticArg,
369+
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
361370
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
362371

363372
error: aborting due to 43 previous errors
364373

365-
For more information about this error, try `rustc --explain E0599`.
374+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)