You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code incorrectly reports that vec needs to be listed as mutable:
use std::cell::RefCell;fnstuff(a:&mutu32){}pubfnmain(){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;fnstuff(a:&mutu32){}pubfnmain(){let vals:Vec<RefCell<u32>> = vec![];// notice the parens + & around vals[0]stuff(&mut*(&vals[0]).borrow_mut());}
Then this will compile successfully.
The text was updated successfully, but these errors were encountered:
This code incorrectly reports that
vec
needs to be listed as mutable:If, however, you change the code slightly:
Then this will compile successfully.
The text was updated successfully, but these errors were encountered: