mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-02 11:29:17 +00:00
56a7e3b707
EventName::mask() turns a leaf variant's discriminant `v` into `1 << (v - 1)`, so the enum can hold at most 64 variants in total — compound "All" variants included, since they consume discriminants even though they own no bit and push every later leaf further up the range. The last variant is KmsServiceStopped at 61, leaving 3 slots. Past the budget, `1u64 << (v - 1)` shifts by 64 or more: debug builds panic with a shift overflow, release builds silently mask the shift amount down and hand back a bit that already belongs to another event. Either failure surfaces far from the line that added the variant. The existing test_mask_bit_budget_is_not_exhausted only bounds the events listed in the test-local ALL_EVENT_NAMES, so a variant nobody remembered to list went unchecked. Add three layers instead: - A const assertion on LAST_EVENT_NAME_VALUE, anchored on the last variant, that fails `cargo build` once the discriminant passes 64. - An exhaustive-match tripwire next to ALL_EVENT_NAMES, so adding a variant breaks compilation with a non-exhaustive-patterns error that points at the budget notes. - Tests pinning that discriminants stay dense and fully listed, that every leaf mask is non-zero and owns a unique bit (catching the release-mode wrapped-shift collision), and that the last variant still lands inside the u64. Document the budget and the three guards on mask() so the next person adding an event sees the remaining headroom. Refs: rustfs/backlog#1572