macros: fix inert attributes from proc_macro_derives with #![feature(proc_macro)] by jseyfried · Pull Request #39572 · rust-lang/rust (original) (raw)

This PR refactors collection of proc_macro_derive invocations to fix #39347.

After this PR, the input to a #[proc_macro_derive] function no longer sees #[derive]s on the underlying item. For example, consider:

extern crate my_derives; use my_derives::{Trait, Trait2};

#[derive(Copy, Clone)] #[derive(Trait)] #[derive(Trait2)] struct S;

Today, the input to the Trait derive is #[derive(Copy, Clone, Trait2)] struct S;, and the input to the Trait2 derive is #[derive(Copy, Clone)] struct S;. More generally, a proc_macro_derive sees all builtin derives, as well as all proc_macro_derives listed after the one being invoked.

After this PR, both Trait and Trait2 will see struct S;.
This is a [breaking-change], but I believe it is highly unlikely to cause breakage in practice.

r? @nrc