Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/operators/cmp_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
let arg_snip = snippet(cx, arg_span, "..");
let expr_snip;
let eq_impl;
if with_deref.is_implemented() {
if with_deref.is_implemented() && !arg_ty.peel_refs().is_str() {
expr_snip = format!("*{arg_snip}");
eq_impl = with_deref;
} else {
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/cmp_owned/with_suggestion.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ impl ToOwned for Baz {
Baz
}
}

fn issue_8103() {
let foo1 = String::from("foo");
let _ = foo1 == "foo";
//~^ cmp_owned
let foo2 = "foo";
let _ = foo1 == foo2;
//~^ cmp_owned
}
9 changes: 9 additions & 0 deletions tests/ui/cmp_owned/with_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ impl ToOwned for Baz {
Baz
}
}

fn issue_8103() {
let foo1 = String::from("foo");
let _ = foo1 == "foo".to_owned();
//~^ cmp_owned
let foo2 = "foo";
let _ = foo1 == foo2.to_owned();
//~^ cmp_owned
}
14 changes: 13 additions & 1 deletion tests/ui/cmp_owned/with_suggestion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,17 @@ error: this creates an owned instance just for comparison
LL | "abc".chars().filter(|c| c.to_owned() != 'X');
| ^^^^^^^^^^^^ help: try: `*c`

error: aborting due to 6 previous errors
error: this creates an owned instance just for comparison
--> tests/ui/cmp_owned/with_suggestion.rs:80:21
|
LL | let _ = foo1 == "foo".to_owned();
| ^^^^^^^^^^^^^^^^ help: try: `"foo"`

error: this creates an owned instance just for comparison
--> tests/ui/cmp_owned/with_suggestion.rs:83:21
|
LL | let _ = foo1 == foo2.to_owned();
| ^^^^^^^^^^^^^^^ help: try: `foo2`

error: aborting due to 8 previous errors

Loading