Closed
Description
use std::ops::{Index, IndexMut};
struct S;
impl S { fn foo(&self) -> i32 { 0 } }
impl Index<usize> for S {
type Output = S;
fn index(&self, _: usize) -> &S { self }
}
impl IndexMut<usize> for S {
fn index_mut(&mut self, _: usize) -> &mut S { self }
}
fn main() {
let s = S;
let _ = &mut s.foo(); // OK
let _ = &mut (&s[0]).foo(); // OK
let _ = &mut s[0].foo(); // error: cannot borrow immutable local variable `s` as mutable
}
The whole example compiles it the IndexMut
implementation is removed.