macros: add #[no_arg]
to skip set_arg
call
A call to `set_arg` is generated for every field of a `SessionDiagnostic` struct without attributes, but not all types support being an argument, so `#[no_arg]` is introduced to skip these fields. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
8100541d54
commit
70ee0c96fc
4 changed files with 45 additions and 2 deletions
|
@ -67,6 +67,7 @@ decl_derive!(
|
|||
warning,
|
||||
error,
|
||||
// field attributes
|
||||
skip_arg,
|
||||
primary_span,
|
||||
label,
|
||||
suggestion,
|
||||
|
|
|
@ -216,7 +216,12 @@ impl<'a> SessionDiagnosticDerive<'a> {
|
|||
if field.attrs.is_empty() {
|
||||
let diag = &builder.diag;
|
||||
let ident = field_binding.ast().ident.as_ref().unwrap();
|
||||
quote! { #diag.set_arg(stringify!(#ident), #field_binding.into_diagnostic_arg()); }
|
||||
quote! {
|
||||
#diag.set_arg(
|
||||
stringify!(#ident),
|
||||
#field_binding.into_diagnostic_arg()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
}
|
||||
|
@ -566,6 +571,11 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
|||
let meta = attr.parse_meta()?;
|
||||
match meta {
|
||||
syn::Meta::Path(_) => match name {
|
||||
"skip_arg" => {
|
||||
// Don't need to do anything - by virtue of the attribute existing, the
|
||||
// `set_arg` call will not be generated.
|
||||
Ok(quote! {})
|
||||
}
|
||||
"primary_span" => {
|
||||
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
|
||||
return Ok(quote! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue