Auto generate values when no values are specified #236
Labels
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-bitflags/bitflags#236
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In some cases, the actual values of the bitfields may not matter to the user, so it would be nice to have another expansion such that:
gets automatically expanded to
Thanks for the suggestion @qwerty01!
This seems reasonable to me. We've got concerns around forwards compatibility where flags inserted in the middle of the enum will change the meaning of any flags that appear after it, but that's already true of
#[repr(n)]enums with default values for variants.Would it be trivial to also allow resetting the counter?
gets automatically expanded to
@shjohnson-pi I think so long as our semantics for what gets inferred is just a left-shift of the previous flag that should work. If in your example you defined
Cas0b0101then we'd still have some idea of what to do next.@KodrAus since 2.0 is out (for the last several months), I guess that means this was rejected for 2.0?
@tech6hutch I think this is something we can add without breakage so it could be introduced at any time.
Is this possible to do with the rules macro, or is a derive macro needed? There are probably some tricks to keep a counter within a rules macro, but that sounds like it could be more trouble then it is worth.
@tgross35 This is not that difficult to implement counter in rule macros, but it can lead to unintuitive and hard to read unfolding code. In fact, more importantly, integrating this functionality into the
bitflagmacro, which is already a rule macro, could make the macro itself difficult to understand and maintain.Maybe that will become more straightforward sometime soon :) https://github.com/rust-lang/rust/pull/122808
(yes yes, MSRV)
I think we could probably also do this using constants, since we already build a constant array of flag values. Constants may be the best approach here since we'll naturally handle
#[cfg]s through them. We could define the semantics as unspecified values are assigned the value at the previous index left-shifted by one (or1if it's the first flag).