- Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Description
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.
Version
$ cargo clippy --version clippy 0.1.81 $ rustc -Vv rustc 1.81.0 (eeb90cda1 2024-09-04) (Fedora 1.81.0-1.fc40) binary: rustc commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c commit-date: 2024-09-04 host: x86_64-unknown-linux-gnu release: 1.81.0 LLVM version: 18.1.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied