Skip to content

rework how [pin_]init! handles cfg - #165

Open
nbdd0121 wants to merge 2 commits into
mainfrom
dev/cfg
Open

rework how [pin_]init! handles cfg#165
nbdd0121 wants to merge 2 commits into
mainfrom
dev/cfg

Conversation

@nbdd0121

Copy link
Copy Markdown
Member

Non-derive proc 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 before expansion.

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 is the same approach as #161 but for init macros. This should hopefully also help #155 by removing the cfg limitation.

Non-derive proc 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 before expansion.

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 is the same approach as commit 3445a65 ("internal: rework how
`#[pin_data]` handles cfg").

Signed-off-by: Gary Guo <gary@garyguo.net>
@nbdd0121
nbdd0121 requested a review from BennoLossin July 30, 2026 11:15
Add a test with 26 cfg options to test linear time behaviour of cfg
resolution. If the cfg-expansion approach is exponential, this test will
cause a timeout.

Signed-off-by: Gary Guo <gary@garyguo.net>
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