diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-12 08:07:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-12 08:07:15 +0100 |
| commit | b18ee9858b01f53b12fdb3aaed704ec2ca785670 (patch) | |
| tree | 4303f607adf95b6c9936b723400265b3cc03296c | |
| parent | 67f21277cd40cd12e69aa34089f4a20926fd6dc5 (diff) | |
| parent | 7c0a7f78a01657c23d23bc4c7e6d3045fd534462 (diff) | |
| download | rust-b18ee9858b01f53b12fdb3aaed704ec2ca785670.tar.gz rust-b18ee9858b01f53b12fdb3aaed704ec2ca785670.zip | |
Rollup merge of #132651 - PonasKovas:master, r=fmease
Remove attributes from generics in built-in derive macros Related issue #132561 Removes all attributes from generics in the expanded implementations of built-in derive macros.
| -rw-r--r-- | compiler/rustc_builtin_macros/src/deriving/generic/mod.rs | 6 | ||||
| -rw-r--r-- | tests/ui/proc-macro/auxiliary/helper-attr.rs | 12 | ||||
| -rw-r--r-- | tests/ui/proc-macro/helper-attr-builtin-derive.rs | 19 |
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() {} |
