Skip to content

Commit

Permalink
remove attributes from generics in built-in derive macros
Browse files Browse the repository at this point in the history
add a test

add github issue link to description of the test

replace new ThinVec with clear()

Co-authored-by: León Orell Valerian Liehr <[email protected]>
  • Loading branch information
PonasKovas and fmease committed Nov 11, 2024
1 parent 096277e commit 7c0a7f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/proc-macro/auxiliary/helper-attr.rs
Original file line number Diff line number Diff line change
@@ -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()
}
19 changes: 19 additions & 0 deletions tests/ui/proc-macro/helper-attr-builtin-derive.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 7c0a7f7

Please sign in to comment.