]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs
Auto merge of #60156 - RalfJung:macos-rand, r=oli-obk,alexcrichton
[rust.git] / src / test / ui / borrowck / borrowck-overloaded-index-move-from-vec.rs
1 #![feature(box_syntax)]
2
3 use std::ops::Index;
4
5 struct MyVec<T> {
6     data: Vec<T>,
7 }
8
9 impl<T> Index<usize> for MyVec<T> {
10     type Output = T;
11
12     fn index(&self, i: usize) -> &T {
13         &self.data[i]
14     }
15 }
16
17 fn main() {
18     let v = MyVec::<Box<_>> { data: vec![box 1, box 2, box 3] };
19     let good = &v[0]; // Shouldn't fail here
20     let bad = v[0];
21     //~^ ERROR cannot move out of borrowed content
22 }