From: Josh Mcguigan Date: Fri, 12 Oct 2018 11:34:41 +0000 (-0700) Subject: cmp_owned correct error message if rhs is deref X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=c9718fa589552476ee277c52a35271663383cf6a;p=rust.git cmp_owned correct error message if rhs is deref --- diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index be863cd7bc8..0a65953313e 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -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", diff --git a/tests/ui/cmp_owned.stderr b/tests/ui/cmp_owned.stderr index 1db60be54d6..a7371ab4b6c 100644 --- a/tests/ui/cmp_owned.stderr +++ b/tests/ui/cmp_owned.stderr @@ -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