rust-marker/design

Disallow bitwise negation inside boolean context

ppershing opened this issue · 1 comments

Lint explanation

Bitwise negation might lead to hard-to-spot errors in case it is confused with a boolean negation.

Example code

let seq_id: u32;
if !seq_id > last_seq_id {/* deal with non-monotonic ids */}

Note that the code above is wrong and the intended code is

let seq_id: u32;
if !(seq_id > last_seq_id) {/* deal with non-monotonic ids */}

Notes

While this lint is very specific to if scenario above, we would be happy with a simple "no bitwise negation" lint as our codebase does not contain much of bit-twiddling.

Marker should already be capable to create such a lint. I would suggest waiting until v0.3.0, which will be released at the start of next month, since there will be several breaking changes in that one. Then we could implement this. :D

I feel like this could also be a good lint for Clippy, as it seems to be generally applicable. It surprised me that if !seq_id > last_seq_id would negate the bits o.O