A value masked with & or | is compared with a constant that the mask can never produce
What it finds
(flags & 4) == 2 is always false: after masking with 4, only bit 2 can be set, and 2 is another bit. Likewise (flags | 1) == 4 is always false, as the result always has bit 0 set. Such a test usually has the wrong mask or the wrong constant. The rule reports == and != between an integer literal and a value masked with an integer literal.
From the rule's source, impossible_mask_test.rs.
class Bits{ bool Wrong(int flags) => (flags & 4) == 2;tx0 reports: (flags & 4) == 2 is always false: the mask cannot give that value bool Right(int flags) => (flags & 4) == 4; bool Or(int flags) => (flags | 1) != 4;tx0 reports: (flags | 1) != 4 is always true: the mask cannot give that value bool Zero(int flags) => (flags & 0x30) == 0x10;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:impossible-mask-test" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:impossible-mask-test] reason="..."tx0 explain tx0/csharp:impossible-mask-test shows the same in the terminal. Found a false positive? Report it.