Bitflags values of zero are considered always present #151
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#151
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?
When a bitflag is built with a zero valued item then it is treated as always present by bitflags functions.
This may cause bugs but it definitely causes confusion when printing such a value. See the following for an example:
Results in an output of:
I noticed this when printing some flags from git2, specifically MergeAnalysis. The output of a
format("{:?}", flag)ended up being "(ANALYSIS_NONE | ANALYSIS_NORMAL | ANALYSIS_FASTFORWARD)" which confused me greatly. ANALYSIS_NONE is zero as that is how it is defined in git2It seems to me that way that flag is intended to be used is that NONE only shows up when there are no other things to set, or maybe as a placeholder and should only appear when nothing else is set.
I agree, a zero value should only show up in Debug output if no bits are set. Would you be interested in sending a PR to fix this?
I would definitely be interested in doing so, where should I start?
The Debug impls are constructed here.
After looking some more at the code I think this is more involved than I thought. With the code considering empty flags as always present I think that changing just the debug output will make for bugs that are even more difficult to track down.
For example
some.contains(Flags::NONE)is always true in my example above, but if we remove it from the debug it will be more difficult to realise this is happening. At leastnone.is_empty()behaves correctly.In any case, I am happy to add this special case if I can also add to the documentation an explanation of zero flags.