rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.37k stars 1.53k forks source link

`bool_comparison` should not fire when testing for false #1043

Open svmnotn opened 8 years ago

svmnotn commented 8 years ago

I think that the bool_comparison lint should not fire when the comparison is var == false because, at least I, find that version much easier to see when quickly scrolling through the code than the !var as it is too simple to miss that single !. However, I'm just putting this here for discussion I'll go turn the lint off in that specific place.

Enjoy your rusty endeavors.

Manishearth commented 8 years ago

Listed in #533

oli-obk commented 8 years ago

@svmnotn I think turning it off for a specific project is the right way to go. But I'd go even further in that case: write a (restriction) lint that forbids !var for booleans. This way you can be sure that your code base doesn't contain the opposite.

golddranks commented 7 years ago

I'd rather have exp == false than !exp, because ! is visually hard to see. The blog post https://eev.ee/blog/2016/12/01/lets-stop-copying-c/#_1 makes excellent point against that.

But even if the style guidelines end up supporting ! over == false, I think that Clippy should lint if there is not whitespace around ! – that at least helps a bit visually.

workingjubilee commented 3 years ago

I came here to add to the lamentations because it is my experience that very often Clippy recommends the ! on expressions like ident.is_cond_true() which is directly against the flow of the overall reading, and in general negative reasoning is harder for me.