Skip to content

Commit 8bc1ded

Browse files
committed
Fix incorrect swap suggestion
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 <[email protected]>
1 parent a3fcaee commit 8bc1ded

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

clippy_lints/src/swap.rs

+8
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
118118
None
119119
}
120120

121+
if let ExprKind::Field(ref lhs1, _) = lhs1.node {
122+
if let ExprKind::Field(ref lhs2, _) = lhs2.node {
123+
if lhs1.hir_id.owner_def_id() == lhs2.hir_id.owner_def_id() {
124+
return;
125+
}
126+
}
127+
}
128+
121129
let (replace, what, sugg) = if let Some((slice, idx1, idx2)) = check_for_slice(cx, lhs1, lhs2) {
122130
if let Some(slice) = Sugg::hir_opt(cx, slice) {
123131
(false,

0 commit comments

Comments
 (0)