Skip to content

Commit fe3519e

Browse files
committed
Swap if branches
1 parent d90cad2 commit fe3519e

File tree

1 file changed

+3
-3
lines changed
  • clippy_lints/src/methods

1 file changed

+3
-3
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,9 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
13331333
let snip;
13341334
if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) {
13351335
// x.clone() might have dereferenced x, possibly through Deref impls
1336-
if cx.tables.expr_ty(arg) != ty {
1336+
if cx.tables.expr_ty(arg) == ty {
1337+
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
1338+
} else {
13371339
let parent = cx.tcx.hir().get_parent_node(expr.id);
13381340
match cx.tcx.hir().get(parent) {
13391341
hir::Node::Expr(parent) => match parent.node {
@@ -1367,8 +1369,6 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
13671369
.count();
13681370
let derefs: String = iter::repeat('*').take(deref_count).collect();
13691371
snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet)));
1370-
} else {
1371-
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
13721372
}
13731373
} else {
13741374
snip = None;

0 commit comments

Comments
 (0)