Rework the #[flag_name] feature and re-stabilize as #[bitflags(flag_name)] #487

Merged
KodrAus merged 10 commits from fix/macro-expansion into main 2026-05-31 16:39:09 -05:00
KodrAus commented 2026-05-31 07:35:04 -05:00 (Migrated from github.com)

Closes #486

In #483, we added macro code to recognize and handle a custom #[flag_name] attribute for setting the name of a flag. This was being expanded under the expr_safe! macro, which already recurses on each attribute on the expression. Combining the two pushed larger bitflags invocations over the default 128 recursion depth limit.

This PR pulls the logic for computing the flag name out of the logic for wrapping expressions, so we recurse to the same depth as before.

Closes #486 In #483, we added macro code to recognize and handle a custom `#[flag_name]` attribute for setting the name of a flag. This was being expanded under the `expr_safe!` macro, which already recurses on each attribute on the expression. Combining the two pushed larger `bitflags` invocations over the default 128 recursion depth limit. This PR pulls the logic for computing the flag name out of the logic for wrapping expressions, so we recurse to the same depth as before.
KodrAus commented 2026-05-31 14:54:40 -05:00 (Migrated from github.com)

While working on this I've also cleaned up the workaround for #320 which has been fixed for a few years now. I've also re-organized our compile-pass tests just for a bit of housekeeping.

While working on this I've also cleaned up the workaround for #320 which has been fixed for a few years now. I've also re-organized our compile-pass tests just for a bit of housekeeping.
KodrAus commented 2026-05-31 15:27:43 -05:00 (Migrated from github.com)

Since we have a second chance to look at this feature, I've namespaced the attribute as #[bitflags(flag_name = "value")] instead of the raw #[flag_name = "value"].

Since we have a second chance to look at this feature, I've namespaced the attribute as `#[bitflags(flag_name = "value")]` instead of the raw `#[flag_name = "value"]`.
xtqqczze commented 2026-09-09 12:03:07 -05:00 (Migrated from github.com)
The https://github.com/bitflags/bitflags/pull/487/commits/e4ed6354c7f31522a42b84dc2fff97ea7c400282 commit appears to trigger an ICE with Rust 1.69, see https://github.com/nix-rust/nix/pull/2812, https://github.com/rust-lang/rust/issues/110848.
Sign in to join this conversation.
No reviewers
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-bitflags/bitflags!487
No description provided.