Closed
Description
This works:
fn main() {
let mut nums=vec![10i,11,12,13];
let index=nums.len()-2;
*nums.get_mut(index)=2;
}
I would like to be able to write this instead:
fn main() {
let mut nums=vec![10i,11,12,13];
*nums.get_mut(nums.len()-2)=2;
}
But:
test.rs:3:16: 3:20 error: cannot borrow `nums` as immutable because it is also borrowed as mutable
test.rs:3 *nums.get_mut(nums.len()-2)=2;
^~~~
test.rs:3:3: 3:7 note: previous borrow of `nums` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `nums` until the borrow ends
test.rs:3 *nums.get_mut(nums.len()-2)=2;
^~~~
Lexically, the receivers appears before the parameters, but semantically it appears later, which is when I'd expect the borrow to happen.
Metadata
Metadata
Assignees
Labels
No labels