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

Is the order of procedural macro attribute execution guaranteed per item? #63336

Closed
azriel91 opened this issue Aug 6, 2019 · 4 comments
Closed
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@azriel91
Copy link
Contributor

azriel91 commented Aug 6, 2019

Hiya, is there an intentional guarantee that procedural macro attributes are executed outward-in per item? To illustrate (repo):

// attr_* appends a new field to the struct

#[attr_0(u8)]
#[attr_1(u16)]
#[attr_2(u32)]
struct Hello;

#[attr_2(u32)]
#[attr_1(u16)]
#[attr_0(u8)]
struct Hello2;

generates:

struct Hello(u8, u16, u32);
struct Hello2(u32, u16, u8);

That's the behaviour, but I'd like to confirm if I can rely on it (and if it should be documented).

#56058 may be related, but I haven't checked the details whether the "each invocation" is per procedural macro (and potentially losing the order guarantee).

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Aug 6, 2019
@Centril
Copy link
Contributor

Centril commented Aug 6, 2019

cc @eddyb @petrochenkov

-- To my knowledge we make no guarantees about the execution order of proc macro expansion.

@ehuss
Copy link
Contributor

ehuss commented Aug 7, 2019

According to rust-lang/reference#578 (comment) it is not defined.

@Mark-Simulacrum
Copy link
Member

That issue seems canonical enough and has a reply from @eddyb so I'm going to close this in favor of the reference (where such things should ultimately be documented anyway, I think).

@Nemo157
Copy link
Member

Nemo157 commented Aug 7, 2019

This isn't really about the execution order of proc-macro-attributes, but rather the application order. Even if all the macros from the example were deterministic and side-effect free the order in which they are applied to the AST will affect the final result.

(But still, this might be better as a reference issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants