Skip to content

Conversation

@Zalathar
Copy link
Member

This PR adds basic support for parsing and applying declarative attribute macros and declarative derive macros, which are supported by rustc behind the #![feature(macro_attr)] and #![feature(macro_derive)] feature gates.

This affects both macro_rules! macros and macro (macros 2.0) macros.

One notable omission is that this PR does not properly support declarative attributes with attribute arguments, as that would require some additional plumbing that I haven't investigated yet, and my main priority is to get derives working. For now, argument-less attribute macros are basically a “free” bonus feature bundled with derive support.

This PR focuses on being able to expand declarative attribute/derive macros internally, so that any items produced by the expansion can be seen by IDE features (e.g. making derived items/impls visible to autocomplete). There might be other relevant IDE features that haven't been fully hooked up or fleshed out.

Fixes #21043 (mostly).

changelog feature

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2025
Comment on lines +621 to +622
let res = match loc.def.kind {
MacroDefKind::Declarative(id, _) => db
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason rustfmt took this extra , _ as a reason to re-indent the entire match. 🤷‍♂️

Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit.

};
}
};
pub(crate) fn macro_styles_from_id(db: &dyn DefDatabase, macro_id: MacroId) -> MacroCallStyles {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this can only return one style, a bit better to return MacroCallStyle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of the function (after the early return for proc macros) can return multiple styles in the MacroExpander::Declarative case.

Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Nov 24, 2025
Merged via the queue into rust-lang:master with commit b5b4aba Nov 24, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2025
@Zalathar Zalathar deleted the derive-macro branch November 24, 2025 23:53
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

Successfully merging this pull request may close these issues.

Declarative attribute/derive macros are not supported

3 participants