about summary refs log tree commit diff
path: root/compiler/rustc_macros/src
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-03-31 09:02:31 +0100
committerDavid Wood <david.wood@huawei.com>2022-04-05 07:01:03 +0100
commit70ee0c96fc29c57f64a6ccfeb66cccf6fac951f7 (patch)
tree01a686fcd042f264200076fb73abc167b90bbc3d /compiler/rustc_macros/src
parent8100541d5496e087ca214df4e599a67a91f25983 (diff)
downloadrust-70ee0c96fc29c57f64a6ccfeb66cccf6fac951f7.tar.gz
rust-70ee0c96fc29c57f64a6ccfeb66cccf6fac951f7.zip
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>
Diffstat (limited to 'compiler/rustc_macros/src')
-rw-r--r--compiler/rustc_macros/src/lib.rs1
-rw-r--r--compiler/rustc_macros/src/session_diagnostic.rs12
2 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs
index b571fdb4ae2..67b56d2e9db 100644
--- a/compiler/rustc_macros/src/lib.rs
+++ b/compiler/rustc_macros/src/lib.rs
@@ -67,6 +67,7 @@ decl_derive!(
         warning,
         error,
         // field attributes
+        skip_arg,
         primary_span,
         label,
         suggestion,
diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs
index 73cd840f0eb..fec9a820d0f 100644
--- a/compiler/rustc_macros/src/session_diagnostic.rs
+++ b/compiler/rustc_macros/src/session_diagnostic.rs
@@ -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! {