]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs
Rollup merge of #107306 - compiler-errors:correct-sugg-for-closure-arg-needs-borrow...
[rust.git] / tests / ui / borrowck / borrowck-overloaded-index-move-from-vec.rs
1 use std::ops::Index;
2
3 struct MyVec<T> {
4     data: Vec<T>,
5 }
6
7 impl<T> Index<usize> for MyVec<T> {
8     type Output = T;
9
10     fn index(&self, i: usize) -> &T {
11         &self.data[i]
12     }
13 }
14
15
16
17 fn main() {
18     let v = MyVec::<Box<_>> { data: vec![Box::new(1), Box::new(2), Box::new(3)] };
19     let good = &v[0]; // Shouldn't fail here
20     let bad = v[0];
21     //~^ ERROR cannot move out of index of `MyVec<Box<i32>>`
22 }