cmp_owned correct error message if rhs is deref

This commit is contained in:
Josh Mcguigan 2018-10-12 04:34:41 -07:00
parent 0b65462ca5
commit c9718fa589
2 changed files with 6 additions and 2 deletions

View file

@ -579,6 +579,10 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
}
}
}
if other_gets_derefed {
db.span_label(lint_span, "try implementing the comparison without allocating");
return;
}
db.span_suggestion_with_applicability(
lint_span,
"try",

View file

@ -40,13 +40,13 @@ error: this creates an owned instance just for comparison
--> $DIR/cmp_owned.rs:42:5
|
42 | y.to_owned() == *x;
| ^^^^^^^^^^^^^^^^^^ help: try: `y == x`
| ^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
error: this creates an owned instance just for comparison
--> $DIR/cmp_owned.rs:47:5
|
47 | y.to_owned() == **x;
| ^^^^^^^^^^^^^^^^^^^ help: try: `y == *x`
| ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
error: this creates an owned instance just for comparison
--> $DIR/cmp_owned.rs:54:9