Skip to content

Commit

Permalink
Fix incorrect swap suggestion
Browse files Browse the repository at this point in the history
Clippy suggests using swap on fields belonging to the same owner
causing two mutable borrows of the owner

Fixes #981

Signed-off-by: Cristian Kubis <cristian.kubis@tsunix.de>
  • Loading branch information
tsurai committed Aug 31, 2019
1 parent a3fcaee commit 8bc1ded
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clippy_lints/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
None
}

if let ExprKind::Field(ref lhs1, _) = lhs1.node {
if let ExprKind::Field(ref lhs2, _) = lhs2.node {
if lhs1.hir_id.owner_def_id() == lhs2.hir_id.owner_def_id() {
return;
}
}
}

let (replace, what, sugg) = if let Some((slice, idx1, idx2)) = check_for_slice(cx, lhs1, lhs2) {
if let Some(slice) = Sugg::hir_opt(cx, slice) {
(false,
Expand Down

0 comments on commit 8bc1ded

Please sign in to comment.