]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-93341.rs
Auto merge of #101629 - compiler-errors:issue-101623, r=sanxiyn
[rust.git] / src / test / ui / generic-associated-types / issue-93341.rs
1 // check-pass
2
3 use std::marker::PhantomData;
4
5 pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>);
6
7 fn new_id() -> Id<'static> {
8     Id(PhantomData)
9 }
10
11 pub trait HasLifetime where {
12     type AtLifetime<'a>;
13 }
14
15 pub struct ExistentialLifetime<S: HasLifetime>(S::AtLifetime<'static>);
16
17 impl<S: HasLifetime> ExistentialLifetime<S> {
18     pub fn new<F>(f: F) -> ExistentialLifetime<S>
19         where for<'id> F: FnOnce(Id<'id>) -> S::AtLifetime<'id> {
20         ExistentialLifetime(f(new_id()))
21     }
22 }
23
24
25 struct ExampleS<'id>(Id<'id>);
26
27 struct ExampleMarker;
28
29 impl HasLifetime for ExampleMarker {
30     type AtLifetime<'id> = ExampleS<'id>;
31 }
32
33
34 fn broken0() -> ExistentialLifetime<ExampleMarker> {
35     fn new_helper<'id>(id: Id<'id>) -> ExampleS<'id> {
36         ExampleS(id)
37     }
38
39     ExistentialLifetime::<ExampleMarker>::new(new_helper)
40 }
41
42 fn broken1() -> ExistentialLifetime<ExampleMarker> {
43     fn new_helper<'id>(id: Id<'id>) -> <ExampleMarker as HasLifetime>::AtLifetime<'id> {
44         ExampleS(id)
45     }
46
47     ExistentialLifetime::<ExampleMarker>::new(new_helper)
48 }
49
50 fn broken2() -> ExistentialLifetime<ExampleMarker> {
51     ExistentialLifetime::<ExampleMarker>::new(|id| ExampleS(id))
52 }
53
54 fn main() {}