Open
Description
I just got the following error (playground):
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
--> src/main.rs:7:9
|
3 | let slice = v.as_slice();
| - immutable borrow occurs here
...
6 | f(slice);
| ----- immutable borrow later used here
7 | v.push(2);
| ^^^^^^^^^ mutable borrow occurs here
The error alone does not give you enough info to see what's going wrong: push
is called after f(slice)
, why is the borrow still active? You need to look at the whole code to realize it's because f
is called in the next loop iteration:
for _ in 0..5 {
f(slice);
v.push(2);
}
It would be nice to include this info in the error - I think there are already some errors that say "borrowed in the next loop iteration".