mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 08:30:45 +00:00
Swap if branches
This commit is contained in:
parent
d90cad24a1
commit
fe3519e0dd
1 changed files with 3 additions and 3 deletions
|
@ -1333,7 +1333,9 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
||||||
let snip;
|
let snip;
|
||||||
if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) {
|
if let Some(snippet) = sugg::Sugg::hir_opt(cx, arg) {
|
||||||
// x.clone() might have dereferenced x, possibly through Deref impls
|
// 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);
|
let parent = cx.tcx.hir().get_parent_node(expr.id);
|
||||||
match cx.tcx.hir().get(parent) {
|
match cx.tcx.hir().get(parent) {
|
||||||
hir::Node::Expr(parent) => match parent.node {
|
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();
|
.count();
|
||||||
let derefs: String = iter::repeat('*').take(deref_count).collect();
|
let derefs: String = iter::repeat('*').take(deref_count).collect();
|
||||||
snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet)));
|
snip = Some(("try dereferencing it", format!("{}{}", derefs, snippet)));
|
||||||
} else {
|
|
||||||
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snip = None;
|
snip = None;
|
||||||
|
|
Loading…
Reference in a new issue