]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/type-param-outlives-reempty-issue-74429-2.rs
Rollup merge of #105955 - Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses...
[rust.git] / src / test / ui / regions / type-param-outlives-reempty-issue-74429-2.rs
1 // Regression test for #74429, where we didn't think that a type parameter
2 // outlived `ReEmpty`.
3
4 // check-pass
5
6 use std::marker::PhantomData;
7 use std::ptr::NonNull;
8
9 pub unsafe trait RawData {
10     type Elem;
11 }
12
13 unsafe impl<A> RawData for OwnedRepr<A> {
14     type Elem = A;
15 }
16
17 unsafe impl<'a, A> RawData for ViewRepr<&'a A> {
18     type Elem = A;
19 }
20
21 pub struct OwnedRepr<A> {
22     ptr: PhantomData<A>,
23 }
24
25 // these Copy impls are not necessary for the repro, but allow the code to compile without error
26 // on 1.44.1
27 #[derive(Copy, Clone)]
28 pub struct ViewRepr<A> {
29     life: PhantomData<A>,
30 }
31
32 #[derive(Copy, Clone)]
33 pub struct ArrayBase<S>
34 where
35     S: RawData,
36 {
37     ptr: NonNull<S::Elem>,
38 }
39
40 pub type Array<A> = ArrayBase<OwnedRepr<A>>;
41
42 pub type ArrayView<'a, A> = ArrayBase<ViewRepr<&'a A>>;
43
44 impl<A, S> ArrayBase<S>
45 where
46     S: RawData<Elem = A>,
47 {
48     pub fn index_axis(&self) -> ArrayView<'_, A> {
49         unimplemented!()
50     }
51
52     pub fn axis_iter<'a>(&'a self) -> std::iter::Empty<&'a A> {
53         unimplemented!()
54     }
55 }
56
57 pub fn x<T: Copy>(a: Array<T>) {
58     // drop just avoids a must_use warning
59     drop((0..1).filter(|_| true));
60     let y = a.index_axis();
61     a.axis_iter().for_each(|_| {
62         drop(y);
63     });
64 }
65
66 fn main() {}