fn main() {
if let Ok(serde_json::Value::Object(x)) = serde_json::from_str("{\"u\":\"\"}") {
if x["u"].to_string() == "\"\"" {
println!("A1");
}
if x["u"] == "\"\"" {
println!("A2");
}
}
}
The above prints only A1 and does not emit A2. cargo clippy suggests
warning: this creates an owned instance just for comparison
--> src/bin/test.rs:3:12
|
3 | if x["u"].to_string() == "\"\"" {
| ^^^^^^^^^^^^^^^^^^ help: try: `x["u"]`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
= note: `#[warn(clippy::cmp_owned)]` on by default
When I replace x["u"].to_string() with x["u"], as clippy suggests, the code does not work any more.
Description
The above prints only
A1
and does not emitA2
.cargo clippy
suggestsWhen I replace
x["u"].to_string()
withx["u"]
, as clippy suggests, the code does not work any more.Version
Additional Labels
No response