Skip to content

Commit c9718fa

Browse files
committed
cmp_owned correct error message if rhs is deref
1 parent 0b65462 commit c9718fa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clippy_lints/src/misc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
579579
}
580580
}
581581
}
582+
if other_gets_derefed {
583+
db.span_label(lint_span, "try implementing the comparison without allocating");
584+
return;
585+
}
582586
db.span_suggestion_with_applicability(
583587
lint_span,
584588
"try",

tests/ui/cmp_owned.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ error: this creates an owned instance just for comparison
4040
--> $DIR/cmp_owned.rs:42:5
4141
|
4242
42 | y.to_owned() == *x;
43-
| ^^^^^^^^^^^^^^^^^^ help: try: `y == x`
43+
| ^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
4444

4545
error: this creates an owned instance just for comparison
4646
--> $DIR/cmp_owned.rs:47:5
4747
|
4848
47 | y.to_owned() == **x;
49-
| ^^^^^^^^^^^^^^^^^^^ help: try: `y == *x`
49+
| ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
5050

5151
error: this creates an owned instance just for comparison
5252
--> $DIR/cmp_owned.rs:54:9

0 commit comments

Comments
 (0)