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 macro has no access to attributes defined before it #1452

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

attribute macro has no access to attributes defined before it #1452

roignpar opened this issue May 13, 2023 · 1 comment

Comments

@roignpar
Copy link

roignpar commented May 13, 2023

Hi! Thank you for syn and all your Rust work!

I ran into this issue while debugging this: roignpar/optfield#4
It seems that attribute macros have no access to attrs defined before them.

#[before]
#[after]
struct Item;

If both before and after are attribute macros:

  • before will have after in Item's attrs field
  • after will not have before in Item's attrs field

The same happens with any kind of attribute in relation to attribute macros.

I haven't tried this with other proc macro types.

Most documentation I could find was here: https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros, but it says that "The second TokenStream is the rest of the item including other attributes on the item."
I couldn't find any mention of attribute order or anything like that.

Is this intended behavior?

@dtolnay
Copy link
Owner

dtolnay commented May 13, 2023

This issue is not related to syn. Syn is not in control of what tokens rustc passes into an attribute macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants