Skip to content

Tracking Issue for RFC 3697 "Declarative macro_rules! attribute macros" (macro_attr) #143547

Description

@joshtriplett

This is a tracking issue for the RFC "Declarative macro_rules! attribute macros" (rust-lang/rfcs#3697).
The feature gate for the issue is #![feature(macro_attr)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

Unresolved Questions

  • Is an attribute macro allowed to recursively invoke itself by emitting the attribute in its output? If there is no technical issue with allowing this, then we should do so, to allow simple recursion (e.g. handling defaults by invoking the same rule as if they were explicitly specified).

  • Are there any places where we currently allow an attribute, but where implementation considerations make it difficult to allow a macro_rules attribute? (For instance, places where we currently allow attributes but don't allow proc-macro attributes.)

  • Before stabilizing this feature, we should make sure it doesn't produce wildly worse error messages in common cases.

  • Before stabilizing this feature, we should receive feedback from crate maintainers, and potentially make further improvements to macro_rules to make it easier to use for their use cases. This feature will provide motivation to evaluate many new use cases that previously weren't written using macro_rules, and we should consider quality-of-life improvements to better support those use cases.

Implementation history

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jul 6, 2025
  2. added
    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.
    T-langRelevant to the language team
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Jul 6, 2025
  3. safinaskar commented on Jul 7, 2025

    @safinaskar
    Contributor

    Is an attribute macro allowed to recursively invoke itself by emitting the attribute in its output? If there is no technical issue with allowing this, then we should do so, to allow simple recursion (e.g. handling defaults by invoking the same rule as if they were explicitly specified).

    As well as I understand, output of proc macros currently is not expanded. (See rust-lang/rfcs#2628 ). And I think this is a bug

  4. joshtriplett commented on Jul 28, 2025

    @joshtriplett
    MemberAuthor

    Initial implementation: #144579

  5. joshtriplett commented on Jul 28, 2025

    @joshtriplett
    MemberAuthor

    @safinaskar A macro_rules attribute re-applying itself seems to work just fine, and I have a test confirming that.

  6. safinaskar commented on Jul 28, 2025

    @safinaskar
    Contributor

    @safinaskar A macro_rules attribute re-applying itself seems to work just fine, and I have a test confirming that.

    You mean that output of macro_attr is expanded? Cool! But then this is inconsistent with proc macros. Proc macros should be fixed, too

  7. joshtriplett commented on Jul 29, 2025

    @joshtriplett
    MemberAuthor

    @safinaskar That sounds like a great thing for someone to work on, in another issue, along with the requisite RFC and crater runs. :)

  8. petrochenkov commented on Aug 1, 2025

    @petrochenkov
    Contributor

    Is an attribute macro allowed to recursively invoke itself by emitting the attribute in its output?

    Macros can generally invoke themselves, and it shouldn't matter much how exactly they were defined, with a proc macro or with macro_rules, and what macro kind they have.

    Are there any places where we currently allow an attribute, but where implementation considerations make it difficult to allow a macro_rules attribute? (For instance, places where we currently allow attributes but don't allow proc-macro attributes.)

    Many locations support only inert attributes and cfg(_attr), but not macro attributes, macro_rules attributes are macro attributes, so they shouldn't be usable in those locations as well.
    See fn supports_macro_expansion in the compiler for the list of specific locations.

  9. added a commit that references this issue on Aug 8, 2025
  10. added a commit that references this issue on Aug 9, 2025
  11. 7 remaining items

  12. added a commit that references this issue on Oct 2, 2025
  13. added a commit that references this issue on Oct 2, 2025
  14. added a commit that references this issue on Oct 2, 2025
  15. added a commit that references this issue on Oct 2, 2025
  16. added a commit that references this issue on Oct 2, 2025
  17. added 3 commits that reference this issue on Nov 8, 2025
  18. added a commit that references this issue on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.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