clippy 0.0.212 (f175352 2019-01-24)
````rust
use serde_json::*;
fn main() {
let object = json!({
"A": ["a", "谩", "脿"],
});
if object["B"][0] == true {}
}
warns
warning: equality checks against true are unnecessary
--> src/main.rs:8:8
|
8 | if object["B"][0] == true {}
| ^^^^^^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: object["B"][0]
|
= note: #[warn(clippy::bool_comparison)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
however
rust
if object["B"][0] {}
does not work:
error[E0308]: mismatched types
--> src/main.rs:8:8
|
8 | if object["B"][0] {}
| ^^^^^^^^^^^^^^ expected bool, found enum serde_json::value::Value
|
= note: expected type bool
found type serde_json::value::Value
error: aborting due to previous error
````
We should probably return early if we can detect that the compared value has its own implementation of PartialEq, like serde_json: https://github.com/serde-rs/json/blob/master/src/value/partial_eq.rs#L93
Why not just check if the left-hand side is bool? The condition must be bool in if expressions Rust.
Most helpful comment
Why not just check if the left-hand side is
bool? The condition must beboolinifexpressions Rust.