Swap if branches

This commit is contained in:
Philipp Hansch 2018-12-08 12:09:32 +01:00
parent d90cad24a1
commit fe3519e0dd
No known key found for this signature in database
GPG key ID: B6FA06A6E0E2665B

View file

@ -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;