Do not recomment cloning explicit &mut expressions

This commit is contained in:
Esteban Küber 2024-03-13 16:35:58 +00:00
parent 5a7caa3174
commit 7f7f6792f1
3 changed files with 5 additions and 24 deletions

View file

@ -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() {