]> git.lizzy.rs Git - rust.git/blob - src/test/ui/typeck/issue-65611.rs
Rollup merge of #82179 - mbartlett21:patch-5, r=joshtriplett
[rust.git] / src / test / ui / typeck / issue-65611.rs
1 use std::mem::MaybeUninit;
2 use std::ops::Deref;
3
4 pub unsafe trait Array {
5     /// The array’s element type
6     type Item;
7     #[doc(hidden)]
8     /// The smallest index type that indexes the array.
9     type Index: Index;
10     #[doc(hidden)]
11     fn as_ptr(&self) -> *const Self::Item;
12     #[doc(hidden)]
13     fn as_mut_ptr(&mut self) -> *mut Self::Item;
14     #[doc(hidden)]
15     fn capacity() -> usize;
16 }
17
18 pub trait Index : PartialEq + Copy {
19     fn to_usize(self) -> usize;
20     fn from(i: usize) -> Self;
21 }
22
23 impl Index for usize {
24     fn to_usize(self) -> usize { self }
25     fn from(val: usize) -> Self {
26         val
27     }
28 }
29
30 unsafe impl<T> Array for [T; 1] {
31     type Item = T;
32     type Index = usize;
33     fn as_ptr(&self) -> *const T { self as *const _ as *const _ }
34     fn as_mut_ptr(&mut self) -> *mut T { self as *mut _ as *mut _}
35     fn capacity() -> usize { 1 }
36 }
37
38 impl<A: Array> Deref for ArrayVec<A> {
39     type Target = [A::Item];
40     #[inline]
41     fn deref(&self) -> &[A::Item] {
42         panic!()
43     }
44 }
45
46 pub struct ArrayVec<A: Array> {
47     xs: MaybeUninit<A>,
48     len: usize,
49 }
50
51 impl<A: Array> ArrayVec<A> {
52     pub fn new() -> ArrayVec<A> {
53         panic!()
54     }
55 }
56
57 fn main() {
58     let mut buffer = ArrayVec::new();
59     let x = buffer.last().unwrap().0.clone();
60     //~^ ERROR type annotations needed
61     //~| ERROR no field `0` on type `&_`
62     buffer.reverse();
63 }