diff options
Diffstat (limited to 'tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs')
-rw-r--r-- | tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs b/tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs new file mode 100644 index 000000000..344d75cc5 --- /dev/null +++ b/tests/ui/borrowck/borrowck-overloaded-index-move-from-vec.rs @@ -0,0 +1,22 @@ +use std::ops::Index; + +struct MyVec<T> { + data: Vec<T>, +} + +impl<T> Index<usize> for MyVec<T> { + type Output = T; + + fn index(&self, i: usize) -> &T { + &self.data[i] + } +} + + + +fn main() { + let v = MyVec::<Box<_>> { data: vec![Box::new(1), Box::new(2), Box::new(3)] }; + let good = &v[0]; // Shouldn't fail here + let bad = v[0]; + //~^ ERROR cannot move out of index of `MyVec<Box<i32>>` +} |