-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint double negation !count != 0
#5794
Comments
This should probably be an enhancement to nonminimal_bool |
Hello, I want to work on this ! But I'm new to open source and would need help getting started |
Hey @sim031999, welcome to Clippy! We have documentation in the https://github.com/rust-lang/rust-clippy/blob/master/doc/common_tools_writing_lints.md This document explains some reoccurring patterns you'll find in Clippy with code examples. If you have any questions, feel free to ask here, in discord, or open a WIP PR. |
Hi @flip1995, I have figured out that the following file ( after line 115) needs changes: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/booleans.rs#L115. But the quine_mc_cluskey technique which is used in it, is not there for !=, can you suggest how do I proceed further? |
You can't use the rust-clippy/clippy_lints/src/booleans.rs Line 68 in bb67423
Maybe not in the |
I think I was mistaken about extending Maybe a better fit would be to add this to bit_mask module since there is a lot of bit comparison logic in there. |
I think the issue meant Replacing @idubrov can you clarify here? |
Right, in my case it was an integer variable, so I made an assumption that expression was parsed as fn main() {
let count = 0;
// Original expression
if !count != 0 {
eprintln!("hello!");
}
// This is what I thought it means to compiler
if !(count != 0) {
eprintln!("hello!");
}
// This compiles? Why???
if (!count) != 0 {
eprintln!("hello!");
}
// This does not compile (makes sens; count is not a `bool`)
if (!count) && true {
eprintln!("hello!");
}
} |
I just saw that I think there is already an issue open for suspicious uses of the |
Ah, got it! The fact that |
Anyway, this is a new lint. The behavior of the lint would be: Lint when there is |
Yeah; now that I understand how it works, it actually turned out to be a logic error in our case! Branch was intended to do |
@rustbot claim |
@rustbot claim |
Opened #12248. |
What it does
I think, clippy should lint the following code:
My brain melts trying to read this expression. It's not that difficult to read, just something immediately throwing me off.
Drawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: