Skip to content

Fix repeated input evaluation in bitflags_match! - #499

Merged
KodrAus merged 1 commit into
bitflags:mainfrom
christophacham:fix/bitflags-match-evaluate-once
Sep 18, 2026
Merged

KodrAus merged 1 commit into
bitflags:mainfrom
christophacham:fix/bitflags-match-evaluate-once

Conversation

@christophacham

@christophacham christophacham commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Evaluate the input once without moving it. Add regression tests for later-arm matches, fallback matches, default-only invocations, and non-Copy inputs. Verified with cargo test --all-features and cargo fmt --all -- --check.

bitflags_match! could evaluate its input repeatedly—once per attempted match—instead of once overall.

So bitflags_match!(next_flags(), …) could call next_flags() several times and match against different values. With only a default arm, it never called it.

The fix evaluates the input once and reuses it without moving it. Four regression tests cover this.

@KodrAus KodrAus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @christophacham!

@KodrAus
KodrAus merged commit 8df4d4e into bitflags:main Sep 18, 2026
10 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