// No particular meaning, just MVCE extracted from larger program
pub fn foo(mut v: Vec<i32>) {
let x = &v[0];
for _ in [0, 1] {
if *x == 0 {
v[0] = 0;
}
}
}
对应的编译错误是:
error[E0502]: cannot borrow v as mutable because it is also borrowed as immutable
--> :5:13
|
2 | let x = &v[0];
| - immutable borrow occurs here
3 | for _ in [0, 1] {
4 | if *x == 0 {
| -- immutable borrow later used here
5 | v[0] = 0;
| ^ mutable borrow occurs here