Skip to content

attribute macros have no access to attributes defined before them #111589

Closed as not planned
@roignpar

Description

@roignpar

While debugging roignpar/optfield#4 I noticed that attribute macros only have access to attributes defined after them. As all the documentation I could find on the subject states that "The second TokenStream is the rest of the item including other attributes on the item", I thought this could be a bug since order of attributes is never mentioned.
It might as well just be missing documentation(?).

I tried this code:

#[before]
#[after]
struct Item;

I expected to see this happen: if after is an attribute macro it would receive #[before] as part of it's item TokenStream.

Instead, this happened: it doesn't.

I initially thought this had something to do with syn: dtolnay/syn#1452

Meta

rustc --version --verbose:

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-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