about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/mod.rs6
-rw-r--r--tests/ui/proc-macro/auxiliary/helper-attr.rs12
-rw-r--r--tests/ui/proc-macro/helper-attr-builtin-derive.rs19
3 files changed, 37 insertions, 0 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index 82baaca9a46..79c198ed2d0 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -680,6 +680,12 @@ impl<'a> TraitDef<'a> {
                     param_clone
                 }
             })
+            .map(|mut param| {
+                // Remove all attributes, because there might be helper attributes
+                // from other macros that will not be valid in the expanded implementation.
+                param.attrs.clear();
+                param
+            })
             .collect();
 
         // and similarly for where clauses
diff --git a/tests/ui/proc-macro/auxiliary/helper-attr.rs b/tests/ui/proc-macro/auxiliary/helper-attr.rs
new file mode 100644
index 00000000000..79ccefd9844
--- /dev/null
+++ b/tests/ui/proc-macro/auxiliary/helper-attr.rs
@@ -0,0 +1,12 @@
+//@ force-host
+//@ no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+// Doesn't do anything, but has a helper attribute.
+#[proc_macro_derive(WithHelperAttr, attributes(x))]
+pub fn derive(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+    proc_macro::TokenStream::new()
+}
diff --git a/tests/ui/proc-macro/helper-attr-builtin-derive.rs b/tests/ui/proc-macro/helper-attr-builtin-derive.rs
new file mode 100644
index 00000000000..eb7292e093c
--- /dev/null
+++ b/tests/ui/proc-macro/helper-attr-builtin-derive.rs
@@ -0,0 +1,19 @@
+// This test checks that helper attributes of a derive proc macro can be used together with
+// other built-in derive macros.
+// issue: rust-lang/rust#132561
+//@ check-pass
+//@ aux-build:helper-attr.rs
+//@ edition:2021
+
+#[macro_use]
+extern crate helper_attr;
+
+use helper_attr::WithHelperAttr;
+
+#[derive(WithHelperAttr, Debug, Clone, PartialEq)]
+struct MyStruct<#[x] 'a, #[x] const A: usize, #[x] B> {
+    #[x]
+    field: &'a [B; A],
+}
+
+fn main() {}