resolve: Properly integrate derives and macro_rules scopes by petrochenkov · Pull Request #63667 · rust-lang/rust (original) (raw)

So,

#[derive(A, B)] struct S;

m!();

turns into something like

struct S;

A_placeholder!( struct S; );

B_placeholder!( struct S; );

m!();

during expansion.

And for m!() its "macro_rules scope" (aka "legacy scope") should point to the B_placeholder call rather than to the derive container #[derive(A, B)].

fn build_reduced_graph now makes sure the legacy scope points to the right thing.
(It's still a mystery for me why this worked before #63535.)

Unfortunately, placeholders from derives are currently treated separately from placeholders from other macros and need to be passed as extra_placeholders rather than a part of the AST fragment.
That's fixable, but I wanted to keep this PR more minimal to close the regression faster.

Fixes #63651
r? @matthewjasper