Closed
Description
This code incorrectly reports that vec
needs to be listed as mutable:
use std::cell::RefCell;
fn stuff(a: &mut u32) {
}
pub fn main() {
let vals: Vec<RefCell<u32>> = vec![];
stuff(&mut *vals[0].borrow_mut());
}
<anon>:9:17: 9:21 error: cannot borrow immutable local variable `vals` as mutable
<anon>:9 stuff(&mut *vals[0].borrow_mut());
^~~~
error: aborting due to previous error
playpen: application terminated with error code 101
If, however, you change the code slightly:
use std::cell::RefCell;
fn stuff(a: &mut u32) {
}
pub fn main() {
let vals: Vec<RefCell<u32>> = vec![];
// notice the parens + & around vals[0]
stuff(&mut *(&vals[0]).borrow_mut());
}
Then this will compile successfully.
Metadata
Metadata
Assignees
Labels
No labels