Treatment of unknown bits in operators is inconsistent #363
Description
The complement
function's documentation says "the returned set contains all the flags which are not set in self
, but which are allowed for this type". So primarily here, the phrase "allowed for this type" is ambiguous; the word "allowed" doesn't appear to be used anywhere else in the documentation, and bitflags in general seems to "allow" bits that aren't defined, with the new from_bits_retain
function.
Looking at the code, it appears complement
does a from_bits_truncate
. Secondarily, I just converted some existing code to bitflags 2.0 and found this behavior surprising. Bitflags allows users to create values with from_bits_retain
, and I assumed that applying !
would act like a plain bitwise complement, and had a debugging adventure trying to figure why code that looked like it was setting a flag wasn't actually setting it.