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

Declarative macro_rules! attribute macros #3697

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

@joshtriplett joshtriplett commented Sep 21, 2024

Many crates provide attribute macros. Today, this requires defining proc
macros, in a separate crate, typically with several additional dependencies
adding substantial compilation time, and typically guarded by a feature that
users need to remember to enable.

However, many common cases of attribute macros don't require any more power
than an ordinary macro_rules! macro. Supporting these common cases would
allow many crates to avoid defining proc macros, reduce dependencies and
compilation time, and provide these macros unconditionally without requiring a
the user to enable a feature.

I've reviewed several existing proc-macro-based attributes in the ecosystem,
and it appears that many would be able to use this feature to avoid needing
proc macros at all.

Rendered

@joshtriplett joshtriplett added the T-lang Relevant to the language team, which will review and decide on the RFC. label Sep 21, 2024
@joshtriplett joshtriplett added the I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. label Sep 22, 2024
@joshtriplett
Copy link
Member Author

Nominated as a follow-up to recent lang discussions about this.

@kennytm
Copy link
Member

kennytm commented Sep 22, 2024

how will this work in macro form? or is rust-lang/rust#39412 decl_macro still a thing

// ok
macro main {
    attr() ($func:item) => { make_async_main!($func) },
    attr(threads = $threads:literal) ($func:item) => { make_async_main!($func, $threads) },
}

// ?
macro stub attr() ($func:item) {
    make_stub_func!($func)
}

@joshtriplett
Copy link
Member Author

@kennytm

how will this work in macro form?

macro is unstable and incomplete; if someone is working on it they can determine that. Your syntax proposal seems like a fine existence proof that it's possible to provide syntax for this.

text/3697-declarative-attribute-macros.md Outdated Show resolved Hide resolved
@joshtriplett
Copy link
Member Author

We had a @rust-lang/lang design meeting today on the set of macro RFCs. I've updated the RFC to incorporate all the feedback from that design meeting.

Per the feedback in that meeting, I'm starting an FCP to start letting people register consensus for this RFC.

@rfcbot merge

@rfcbot
Copy link
Collaborator

rfcbot commented Nov 21, 2024

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Nov 21, 2024
madsmtm added a commit to madsmtm/objc2 that referenced this pull request Nov 22, 2024
Instead of specifying `impl ClassType for ...`, we instead parse the
custom attributes `#[unsafe(super(...))]`, `#[thread_kind = ...]` and
`#[name = ...]`.

This is nice because:
- It's more concise.
- It more closely matches what we might end up with once it can become
  and attribute macro:
  rust-lang/rfcs#3697
- We need to parse the attributes anyhow to override derives:
  #267

  (The extern_class! part of that issue is now resolved).
- It makes it easier to change ClassType in the future without having to
  change the macro API as well.

Additionally, this commit also adds incomplete support for generics, to
avoid the framework crates depending on an internal macro, and it
improves rust-analyzer support in extern_class! by having more relaxed
parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants