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 <david.wood@huawei.com>
This commit is contained in:
parent
b5545f1b0c
commit
de3e8ca2f3
6 changed files with 22 additions and 13 deletions
|
@ -821,9 +821,9 @@ impl Diagnostic {
|
||||||
pub fn set_arg(
|
pub fn set_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<Cow<'static, str>>,
|
name: impl Into<Cow<'static, str>>,
|
||||||
arg: DiagnosticArgValue<'static>,
|
arg: impl IntoDiagnosticArg,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.args.push((name.into(), arg));
|
self.args.push((name.into(), arg.into_diagnostic_arg()));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::diagnostic::DiagnosticArgValue;
|
use crate::diagnostic::IntoDiagnosticArg;
|
||||||
use crate::{Diagnostic, DiagnosticId, DiagnosticMessage, DiagnosticStyledString, ErrorGuaranteed};
|
use crate::{Diagnostic, DiagnosticId, DiagnosticMessage, DiagnosticStyledString, ErrorGuaranteed};
|
||||||
use crate::{Handler, Level, MultiSpan, StashKey};
|
use crate::{Handler, Level, MultiSpan, StashKey};
|
||||||
use rustc_lint_defs::Applicability;
|
use rustc_lint_defs::Applicability;
|
||||||
|
@ -528,7 +528,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
forward!(pub fn set_arg(
|
forward!(pub fn set_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: impl Into<Cow<'static, str>>,
|
name: impl Into<Cow<'static, str>>,
|
||||||
arg: DiagnosticArgValue<'static>,
|
arg: impl IntoDiagnosticArg,
|
||||||
) -> &mut Self);
|
) -> &mut Self);
|
||||||
|
|
||||||
forward!(pub fn subdiagnostic(
|
forward!(pub fn subdiagnostic(
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
|
||||||
quote! {
|
quote! {
|
||||||
#diag.set_arg(
|
#diag.set_arg(
|
||||||
stringify!(#ident),
|
stringify!(#ident),
|
||||||
#field_binding.into_diagnostic_arg()
|
#field_binding
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -349,7 +349,7 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
|
||||||
let generated = quote! {
|
let generated = quote! {
|
||||||
#diag.set_arg(
|
#diag.set_arg(
|
||||||
stringify!(#ident),
|
stringify!(#ident),
|
||||||
#binding.into_diagnostic_arg()
|
#binding
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,7 @@ struct ErrorWithDefaultLabelAttr<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
//~^ ERROR no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
|
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
|
||||||
#[error(code = "E0123", slug = "foo")]
|
#[error(code = "E0123", slug = "foo")]
|
||||||
struct ArgFieldWithoutSkip {
|
struct ArgFieldWithoutSkip {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
|
@ -349,17 +349,26 @@ error: cannot find attribute `nonsense` in this scope
|
||||||
LL | #[nonsense]
|
LL | #[nonsense]
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope
|
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
|
||||||
--> $DIR/diagnostic-derive.rs:329:10
|
--> $DIR/diagnostic-derive.rs:329:10
|
||||||
|
|
|
|
||||||
LL | struct Hello {}
|
|
||||||
| ------------ method `into_diagnostic_arg` not found for this
|
|
||||||
...
|
|
||||||
LL | #[derive(SessionDiagnostic)]
|
LL | #[derive(SessionDiagnostic)]
|
||||||
| ^^^^^^^^^^^^^^^^^ method not found in `Hello`
|
| ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
|
||||||
|
|
|
|
||||||
|
= help: the following other types implement trait `IntoDiagnosticArg`:
|
||||||
|
&'a str
|
||||||
|
Ident
|
||||||
|
String
|
||||||
|
Symbol
|
||||||
|
rustc_middle::ty::Ty<'tcx>
|
||||||
|
usize
|
||||||
|
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
|
||||||
|
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:531:19
|
||||||
|
|
|
||||||
|
LL | arg: impl IntoDiagnosticArg,
|
||||||
|
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
|
||||||
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 43 previous errors
|
error: aborting due to 43 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0599`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue