Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow bitwise negation inside boolean context #46

Open
ppershing opened this issue Sep 19, 2023 · 1 comment
Open

Disallow bitwise negation inside boolean context #46

ppershing opened this issue Sep 19, 2023 · 1 comment
Labels
A-user-story Area: A user story or a related issue

Comments

@ppershing
Copy link

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.

@ppershing ppershing added the A-user-story Area: A user story or a related issue label Sep 19, 2023
@xFrednet
Copy link
Member

xFrednet commented Sep 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-user-story Area: A user story or a related issue
Projects
None yet
Development

No branches or pull requests

2 participants