Skip to content

internal: rework how #[pin_data] handles cfg#161

Open
nbdd0121 wants to merge 1 commit into
mainfrom
dev/cfg
Open

internal: rework how #[pin_data] handles cfg#161
nbdd0121 wants to merge 1 commit into
mainfrom
dev/cfg

Conversation

@nbdd0121

Copy link
Copy Markdown
Member

I'm unhappy about the cfg handling in #155, and when working on self-referential pin-init the conditional existence of fields become annoying as well. So here's an alternative way of handling this.

cc @mqqz


Attribute macros are invoked without cfg being resolved. This adds quite a bit complexity to the macro because all of the macro needs to be careful to attach necessary cfgs. This becomes especially tricky for tuple structs. Thus, it is convenient if cfgs are all resolved like derive macros.

The most optimal way to handle this is via TokenStream::expand_expr, but that is still unstable. Implement an approach where we generate two cfg-gated macro invocations with cfg resolved within the invocation. This would mean when the loop falls through, all field cfgs are resolved, so remove all handling of cfg_attrs for the rest of the macro.

Attribute macros are invoked without cfg being resolved. This adds quite a
bit complexity to the macro because all of the macro needs to be careful to
attach necessary cfgs. This becomes especially tricky for tuple structs. Thus,
it is convenient if cfgs are all resolved like derive macros.

The most optimal way to handle this is via `TokenStream::expand_expr`, but that is still unstable.
Implement an approach where we generate two cfg-gated macro invocations with cfg
resolved within the invocation. This would mean when the loop falls through, all field cfgs
are resolved, so remove all handling of cfg_attrs for the rest of the macro.

Signed-off-by: Gary Guo <gary@garyguo.net>
@nbdd0121 nbdd0121 requested a review from BennoLossin July 13, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant