Basic support for declarative attribute/derive macros#21121
Merged
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom Nov 24, 2025
Merged
Basic support for declarative attribute/derive macros#21121ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
Conversation
Zalathar
commented
Nov 24, 2025
Comment on lines
+621
to
+622
| let res = match loc.def.kind { | ||
| MacroDefKind::Declarative(id, _) => db |
Member
Author
There was a problem hiding this comment.
For some reason rustfmt took this extra , _ as a reason to re-indent the entire match. 🤷♂️
ChayimFriedman2
approved these changes
Nov 24, 2025
| }; | ||
| } | ||
| }; | ||
| pub(crate) fn macro_styles_from_id(db: &dyn DefDatabase, macro_id: MacroId) -> MacroCallStyles { |
Contributor
There was a problem hiding this comment.
Since this can only return one style, a bit better to return MacroCallStyle.
Member
Author
There was a problem hiding this comment.
The second part of the function (after the early return for proc macros) can return multiple styles in the MacroExpander::Declarative case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andmacro(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