3 #![feature(generic_associated_types)]
4 use std::marker::PhantomData;
6 pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>);
8 fn new_id() -> Id<'static> {
12 pub trait HasLifetime where {
16 pub struct ExistentialLifetime<S: HasLifetime>(S::AtLifetime<'static>);
18 impl<S: HasLifetime> ExistentialLifetime<S> {
19 pub fn new<F>(f: F) -> ExistentialLifetime<S>
20 where for<'id> F: FnOnce(Id<'id>) -> S::AtLifetime<'id> {
21 ExistentialLifetime(f(new_id()))
26 struct ExampleS<'id>(Id<'id>);
30 impl HasLifetime for ExampleMarker {
31 type AtLifetime<'id> = ExampleS<'id>;
35 fn broken0() -> ExistentialLifetime<ExampleMarker> {
36 fn new_helper<'id>(id: Id<'id>) -> ExampleS<'id> {
40 ExistentialLifetime::<ExampleMarker>::new(new_helper)
43 fn broken1() -> ExistentialLifetime<ExampleMarker> {
44 fn new_helper<'id>(id: Id<'id>) -> <ExampleMarker as HasLifetime>::AtLifetime<'id> {
48 ExistentialLifetime::<ExampleMarker>::new(new_helper)
51 fn broken2() -> ExistentialLifetime<ExampleMarker> {
52 ExistentialLifetime::<ExampleMarker>::new(|id| ExampleS(id))