Skip to content

bitflags: allow parsing unnamed ("_") bitflags#1169

Merged
emilio merged 2 commits into
mozilla:mainfrom
nullstalgia:fix/unnamed-bitflags
Jul 10, 2026
Merged

bitflags: allow parsing unnamed ("_") bitflags#1169
emilio merged 2 commits into
mozilla:mainfrom
nullstalgia:fix/unnamed-bitflags

Conversation

@nullstalgia

Copy link
Copy Markdown
Contributor

To avoid potentially truncating unknown bits within the derived methods, the documentation recommends adding an unnamed flag with all bits set. This commit allows cbindgen to skip parsing those flags without throwing an error (like it did previously, then skipping the entire item!), and only emit the named flags with values.

Before:

WARN: Failed to parse bitflags invocation: Error("expected identifier, found keyword `_`")
...
typedef uint8_t Flags;

After:

INFO: Take my_crate::Flags.
DEBUG: Continuing past unnamed bitflag
INFO: Take my_crate::Flags::A.
INFO: Take my_crate::Flags::B.
INFO: Take my_crate::Flags::C.
INFO: Take my_crate::Flags::D.
...
typedef uint8_t Flags;
#define Flags_A (uint8_t)(1 << 0)
#define Flags_B (uint8_t)(1 << 1)
#define Flags_C (uint8_t)(1 << 2)
#define Flags_D (uint8_t)(1 << 3)

I'm unsure if unraw() would be needed due to my use of the IdentExt::parse_any, might be worth adding as a test case?

And in order to pass cargo clippy with yesterday's Stable release (1.97.0), I had to do another commit with some fixes. Let me know if you'd prefer a cleaner history.

To avoid potentially truncating unknown bits within the derived methods,
the documentation recommends adding an unnamed flag with all bits set.
This commit allows cbindgen to parse those flags without throwing an
error (like it did previously).

@emilio emilio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

Merged via the queue into mozilla:main with commit df45c23 Jul 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants