about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-03-13 16:35:58 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-04-11 16:41:41 +0000
commit7f7f6792f161d8b7f383ca18a1d820d2ca811bc4 (patch)
tree7960c531ba7bcec4352d4cba1c6c6d125201a1f1 /compiler/rustc_borrowck
parent5a7caa3174f8174db817228d8c2a02aa4913095c (diff)
downloadrust-7f7f6792f161d8b7f383ca18a1d820d2ca811bc4.tar.gz
rust-7f7f6792f161d8b7f383ca18a1d820d2ca811bc4.zip
Do not recomment cloning explicit `&mut` expressions
Diffstat (limited to 'compiler/rustc_borrowck')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index c385fb583bb..7c4623e6ea7 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -1033,6 +1033,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         while let hir::ExprKind::AddrOf(.., inner) | hir::ExprKind::Unary(hir::UnOp::Deref, inner) =
             &inner_expr.kind
         {
+            if let hir::ExprKind::AddrOf(_, hir::Mutability::Mut, _) = inner_expr.kind {
+                // We assume that `&mut` refs are desired for their side-effects, so cloning the
+                // value wouldn't do what the user wanted.
+                return;
+            }
             inner_expr = inner;
         }
         if inner_expr.span.lo() != expr.span.lo() {