Skip to content

#[derive(...)] doesn't invalidate tokens for nested items #81099

Closed
@petrochenkov

Description

@petrochenkov

Reproduction:

// check-pass
// aux-build:test-macros.rs

#![feature(stmt_expr_attributes)]
#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate test_macros;

#[derive(PartialEq, Eq)]
struct S {
    field: [u8; #[print_attr] {
        #[cfg(FALSE)] { 10 }
        #[cfg(not(FALSE))]  { 11 }
    }],
}

fn main() {}

#[derive] will fully configure the item S and remove #[cfg(FALSE)] { 10 } before outputting the item or passing it to PartialEq and Eq.
#[print_attr] however will print tokens for both cfg cases because its input tokens are not invalidated and are stale.

Fix:

  • #[derive] should walk the whole input item and invalidate tokens for all nested nodes, not only for the item itself.
  • Attribute macros should be ready to face input with no tokens and use CanSynthesizeMissingTokens::Yes.

cc @Aaron1011

Metadata

Metadata

Assignees

Labels

A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions