Do not recomment cloning explicit &mut
expressions
This commit is contained in:
parent
5a7caa3174
commit
7f7f6792f1
@ -1033,6 +1033,11 @@ fn suggest_cloning_inner(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Ex
|
|||||||
while let hir::ExprKind::AddrOf(.., inner) | hir::ExprKind::Unary(hir::UnOp::Deref, inner) =
|
while let hir::ExprKind::AddrOf(.., inner) | hir::ExprKind::Unary(hir::UnOp::Deref, inner) =
|
||||||
&inner_expr.kind
|
&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;
|
inner_expr = inner;
|
||||||
}
|
}
|
||||||
if inner_expr.span.lo() != expr.span.lo() {
|
if inner_expr.span.lo() != expr.span.lo() {
|
||||||
|
@ -11,12 +11,6 @@ LL | println!("{}", f[s]);
|
|||||||
...
|
...
|
||||||
LL | use_mut(rs);
|
LL | use_mut(rs);
|
||||||
| -- borrow later used here
|
| -- borrow later used here
|
||||||
|
|
|
||||||
help: consider cloning the value if the performance cost is acceptable
|
|
||||||
|
|
|
||||||
LL - let rs = &mut s;
|
|
||||||
LL + let rs = s.clone();
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0505]: cannot move out of `s` because it is borrowed
|
error[E0505]: cannot move out of `s` because it is borrowed
|
||||||
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
||||||
@ -31,12 +25,6 @@ LL | f[s] = 10;
|
|||||||
...
|
...
|
||||||
LL | use_mut(rs);
|
LL | use_mut(rs);
|
||||||
| -- borrow later used here
|
| -- borrow later used here
|
||||||
|
|
|
||||||
help: consider cloning the value if the performance cost is acceptable
|
|
||||||
|
|
|
||||||
LL - let rs = &mut s;
|
|
||||||
LL + let rs = s.clone();
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0382]: use of moved value: `s`
|
error[E0382]: use of moved value: `s`
|
||||||
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
||||||
|
@ -27,12 +27,6 @@ LL | let z = x;
|
|||||||
| ^ move out of `x` occurs here
|
| ^ move out of `x` occurs here
|
||||||
LL | y
|
LL | y
|
||||||
| - returning this value requires that `*x` is borrowed for `'1`
|
| - returning this value requires that `*x` is borrowed for `'1`
|
||||||
|
|
|
||||||
help: consider cloning the value if the performance cost is acceptable
|
|
||||||
|
|
|
||||||
LL - let y = &mut *x;
|
|
||||||
LL + let y = x.clone();
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0505]: cannot move out of `s` because it is borrowed
|
error[E0505]: cannot move out of `s` because it is borrowed
|
||||||
--> $DIR/polonius-smoke-test.rs:42:5
|
--> $DIR/polonius-smoke-test.rs:42:5
|
||||||
@ -46,12 +40,6 @@ LL | s;
|
|||||||
| ^ move out of `s` occurs here
|
| ^ move out of `s` occurs here
|
||||||
LL | tmp;
|
LL | tmp;
|
||||||
| --- borrow later used here
|
| --- borrow later used here
|
||||||
|
|
|
||||||
help: consider cloning the value if the performance cost is acceptable
|
|
||||||
|
|
|
||||||
LL - let r = &mut *s;
|
|
||||||
LL + let r = s.clone();
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user