-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Basic support for declarative attribute/derive macros #21121
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
Conversation
| let res = match loc.def.kind { | ||
| MacroDefKind::Declarative(id, _) => db |
There was a problem hiding this comment.
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. 🤷♂️
ChayimFriedman2
left a comment
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ChayimFriedman2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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