Skip to content

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

Closed
@azriel91

Description

@azriel91

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions