Mention split_at_mut when mixing mutability in indexing ops

Emit suggestion when encountering

```rust
let a = &mut foo[0];
let b = &foo[1];
a.use_mut();
```
This commit is contained in:
Esteban Küber 2024-04-24 18:14:37 +00:00
parent dbaa4e2148
commit 9f9f0aa534
4 changed files with 106 additions and 4 deletions

View file

@ -1527,7 +1527,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow },
) => {
first_borrow_desc = "mutable ";
self.cannot_reborrow_already_borrowed(
let mut err = self.cannot_reborrow_already_borrowed(
span,
&desc_place,
&msg_place,
@ -1537,7 +1537,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"mutable",
&msg_borrow,
None,
)
);
self.suggest_slice_method_if_applicable(
&mut err,
place,
issued_borrow.borrowed_place,
span,
issued_span,
);
err
}
(
BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow },
@ -1555,6 +1563,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&msg_borrow,
None,
);
self.suggest_slice_method_if_applicable(
&mut err,
place,
issued_borrow.borrowed_place,
span,
issued_span,
);
self.suggest_binding_for_closure_capture_self(&mut err, &issued_spans);
self.suggest_using_closure_argument_instead_of_capture(
&mut err,