]> git.lizzy.rs Git - rust.git/commitdiff
Fix incorrect swap suggestion
authorCristian Kubis <cristian.kubis@tsunix.de>
Sat, 31 Aug 2019 16:50:22 +0000 (18:50 +0200)
committerCristian Kubis <cristian.kubis@tsunix.de>
Sat, 31 Aug 2019 16:53:14 +0000 (18:53 +0200)
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>
clippy_lints/src/swap.rs

index 80c9a33c06a807bdac2915c31a8a94350b9918db..79ff183c9ca3288411bd3643d69efd1762086252 100644 (file)
@@ -118,6 +118,14 @@ fn check_for_slice<'a>(
                     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,