rust/tests/ui/suggestions/suggest-split-at-mut.stderr
Esteban Küber 386236f289 Detect borrow error involving sub-slices and suggest split_at_mut
```
error[E0499]: cannot borrow `foo` as mutable more than once at a time
  --> $DIR/suggest-split-at-mut.rs:13:18
   |
LL |     let a = &mut foo[..2];
   |                  --- first mutable borrow occurs here
LL |     let b = &mut foo[2..];
   |                  ^^^ second mutable borrow occurs here
LL |     a[0] = 5;
   |     ---- first borrow later used here
   |
   = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```

Address most of #58792.

For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25 16:55:32 +00:00

29 lines
1.1 KiB
Plaintext

error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time
--> $DIR/suggest-split-at-mut.rs:4:13
|
LL | let a = &mut foo[2];
| ----------- first mutable borrow occurs here
LL | let b = &mut foo[3];
| ^^^^^^^^^^^ second mutable borrow occurs here
LL | *a = 5;
| ------ first borrow later used here
|
= help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
= help: consider using `.swap(index_1, index_2)` to swap elements at the specified indices
error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/suggest-split-at-mut.rs:13:18
|
LL | let a = &mut foo[..2];
| --- first mutable borrow occurs here
LL | let b = &mut foo[2..];
| ^^^ second mutable borrow occurs here
LL | a[0] = 5;
| ---- first borrow later used here
|
= help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0499`.