1 // Check that we properly record borrows when we are doing an
2 // overloaded, autoderef of a value obtained via an overloaded index
3 // operator. The accounting of the all the implicit things going on
4 // here is rather subtle. Issue #20232.
6 use std::ops::{Deref, Index};
8 struct MyVec<T> { x: T }
10 impl<T> Index<usize> for MyVec<T> {
12 fn index(&self, _: usize) -> &T {
17 struct MyPtr<T> { x: T }
19 impl<T> Deref for MyPtr<T> {
21 fn deref(&self) -> &T {
26 struct Foo { f: usize }
29 let mut v = MyVec { x: MyPtr { x: Foo { f: 22 } } };
31 v = MyVec { x: MyPtr { x: Foo { f: 23 } } };
32 //~^ ERROR cannot assign to `v` because it is borrowed