-
-
Notifications
You must be signed in to change notification settings - Fork 260
Prevent procedural macro hygiene issue with eager macros #1397
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
Prevent procedural macro hygiene issue with eager macros #1397
Conversation
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1397 |
|
Thanks a lot, great discovery and super nice that it's so simple to fix. Span improvements are always appreciated; we started with #1370 and #1373, but there is a lot left to do 🙂 Could you add a comment about macro hygiene (and maybe a link to this PR) above the changed lines, so that we don't risk accidentally re-introducing it again? Please squash commits with existing one. Do you think there's a way to test this without depending on |
401e0f3 to
5bcb419
Compare
This PR adds a change which links together identifiers in `quote!` expansion. While in normal context, there's no issues with expansion of procedural macro `#[func]` attribute, Rust macro hygiene rules start to apply within the context of `eager2` crate.
5bcb419 to
7b9b5cc
Compare
|
@Bromeon Added a comment about the requirement to provide spans to the identifiers with a link to this PR for context, is the explanation for it correct? I haven't reproduce the issue outside of |
Bromeon
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!
OK, that's probably the end of the line for our macOS Intel support 🥲 |
This PR adds a change which links together identifiers in
quote!expansion. While in normal context, there's no issues with expansion of procedural macro#[func]attribute, Rust macro hygiene rules start to apply within the context ofeager2crate.Context/use case
I'm using
eager2crate to implement makeshift mixin pattern for exported GDExtension classes. This allows to define 'interface' as macro once, and then apply the same#[func]/#[signal]/#[property]'signature' to multiple exported classes, embedding it as tokens (so#[godot_api]is able to catch the#[func]attribute).Even beyond this use case,
eager2macro is overall infinitely useful and powerful, as it allows to define and perform eager macro expansion (similar to built-in ones, such asconcat) - there's a chance that similar functionality will make it into 'declarative macros 2.0' proposal in Rust language some time later.However, recent changes to the
#[func]attribute expansion started causing this type of error:So during the expansion of
#[godot_api]withineagercontext, hygiene rule forparamstrigger, preventing the compiler from matching the identifier referenced with#param_identtoparams. Use of consistent identifier reference (#param_identin both argument list and function body, with samespan) prevents this issue and allows to keep using the eager expansion.