Let\'s try to compile this code:
use std::cell::RefCell;
struct Foo {
v: Vec>,
}
impl Foo {
fn f(&self, i: usize) {
This is a known issue where IndexMut
is sometimes selected when Index
should actually be used.
Your workaround of using {}
is reasonable, but you can also use Index
explicitly:
use std::cell::RefCell;
fn f(v: Vec<RefCell<u8>>) {
use std::ops::Index;
let _t = &mut v.index(0).borrow_mut();
}
fn main() {}
See also:
Another workaround is to explicitly call RefCell::borrow_mut(&v[0])
.