summaryrefslogtreecommitdiff
path: root/tests/ui/regions/type-param-outlives-reempty-issue-74429-2.rs
blob: a65c17e0efc3c4bd11cee161dd240f4e3fc09947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Regression test for #74429, where we didn't think that a type parameter
// outlived `ReEmpty`.

// check-pass

use std::marker::PhantomData;
use std::ptr::NonNull;

pub unsafe trait RawData {
    type Elem;
}

unsafe impl<A> RawData for OwnedRepr<A> {
    type Elem = A;
}

unsafe impl<'a, A> RawData for ViewRepr<&'a A> {
    type Elem = A;
}

pub struct OwnedRepr<A> {
    ptr: PhantomData<A>,
}

// these Copy impls are not necessary for the repro, but allow the code to compile without error
// on 1.44.1
#[derive(Copy, Clone)]
pub struct ViewRepr<A> {
    life: PhantomData<A>,
}

#[derive(Copy, Clone)]
pub struct ArrayBase<S>
where
    S: RawData,
{
    ptr: NonNull<S::Elem>,
}

pub type Array<A> = ArrayBase<OwnedRepr<A>>;

pub type ArrayView<'a, A> = ArrayBase<ViewRepr<&'a A>>;

impl<A, S> ArrayBase<S>
where
    S: RawData<Elem = A>,
{
    pub fn index_axis(&self) -> ArrayView<'_, A> {
        unimplemented!()
    }

    pub fn axis_iter<'a>(&'a self) -> std::iter::Empty<&'a A> {
        unimplemented!()
    }
}

pub fn x<T: Copy>(a: Array<T>) {
    // drop just avoids a must_use warning
    drop((0..1).filter(|_| true));
    let y = a.index_axis();
    a.axis_iter().for_each(|_| {
        drop(y);
    });
}

fn main() {}