diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 57eb5c539bc..d311f76074c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1333,7 +1333,9 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp let snip; if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) { // x.clone() might have dereferenced x, possibly through Deref impls - if cx.tables.expr_ty(arg) != ty { + if cx.tables.expr_ty(arg) == ty { + snip = Some(("try removing the `clone` call", format!("{}", snippet))); + } else { let parent = cx.tcx.hir().get_parent_node(expr.id); match cx.tcx.hir().get(parent) { hir::Node::Expr(parent) => match parent.node { @@ -1367,8 +1369,6 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp .count(); let derefs: String = iter::repeat('*').take(deref_count).collect(); snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet))); - } else { - snip = Some(("try removing the `clone` call", format!("{}", snippet))); } } else { snip = None;