3 use std::marker::PhantomData;
5 pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>);
7 fn new_id() -> Id<'static> {
11 pub trait HasLifetime where {
15 pub struct ExistentialLifetime<S: HasLifetime>(S::AtLifetime<'static>);
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()))
25 struct ExampleS<'id>(Id<'id>);
29 impl HasLifetime for ExampleMarker {
30 type AtLifetime<'id> = ExampleS<'id>;
34 fn broken0() -> ExistentialLifetime<ExampleMarker> {
35 fn new_helper<'id>(id: Id<'id>) -> ExampleS<'id> {
39 ExistentialLifetime::<ExampleMarker>::new(new_helper)
42 fn broken1() -> ExistentialLifetime<ExampleMarker> {
43 fn new_helper<'id>(id: Id<'id>) -> <ExampleMarker as HasLifetime>::AtLifetime<'id> {
47 ExistentialLifetime::<ExampleMarker>::new(new_helper)
50 fn broken2() -> ExistentialLifetime<ExampleMarker> {
51 ExistentialLifetime::<ExampleMarker>::new(|id| ExampleS(id))