Suggest split_at_mut on multiple mutable index access
This commit is contained in:
parent
994e5e7465
commit
0f73133be6
3 changed files with 48 additions and 2 deletions
8
src/test/ui/suggestions/suggest-split-at-mut.rs
Normal file
8
src/test/ui/suggestions/suggest-split-at-mut.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fn main() {
|
||||
let mut foo = [1, 2, 3, 4];
|
||||
let a = &mut foo[2];
|
||||
let b = &mut foo[3]; //~ ERROR cannot borrow `foo[_]` as mutable more than once at a time
|
||||
*a = 5;
|
||||
*b = 6;
|
||||
println!("{:?} {:?}", a, b);
|
||||
}
|
||||
15
src/test/ui/suggestions/suggest-split-at-mut.stderr
Normal file
15
src/test/ui/suggestions/suggest-split-at-mut.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0499`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue