Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
roignpar opened this issue May 15, 2023 · 1 comment
Closed

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

roignpar opened this issue May 15, 2023 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@roignpar
Copy link

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
@roignpar roignpar added the C-bug Category: This is a bug. label May 15, 2023
@ehuss
Copy link
Contributor

ehuss commented May 15, 2023

We haven't definitively documented what a proc-macro sees, but it will most likely be that attributes see the inert attributes that follow them. I'm going to close as a duplicate of rust-lang/reference#692, since this seems like a documentation issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants