Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Higher ranked lifetimes cannot cross type boundaries #28721

Closed
Diggsey opened this issue Sep 29, 2015 · 3 comments
Closed

Higher ranked lifetimes cannot cross type boundaries #28721

Diggsey opened this issue Sep 29, 2015 · 3 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@Diggsey
Copy link
Contributor

Diggsey commented Sep 29, 2015

This currently does not compile:

struct Message<'a> {
    data: &'a u32,
}

struct Handler<T>(Option<Box<Fn(T)>>);

struct Cfg {
    handler: for<'a> Handler<Message<'a>>, // error: `Handler` is not a trait [E0404]
}

This precludes a lot of useful patterns.

@eefriedman
Copy link
Contributor

What you've written isn't really what you want... what you want is something more like:

struct Message<'a> {
    data: &'a u32,
}

// The second for<> is written out for clarity, but could be elided.
struct Handler<for<'a> T<'a>>(Option<Box<for<'a> Fn(T<'a>)>>);

struct Cfg {
    handler: Handler<Message>,
}

That's completely reasonable... but sort of complicated to implement. Possibly a duplicate of rust-lang/rfcs#324 .

@Diggsey
Copy link
Contributor Author

Diggsey commented Sep 29, 2015

Ah, I was wondering if this was the same as HKT or not: the frustrating part about this it's that it's already possible if you get rid of Handler and always write the signature in full, so it feels like a failure of the language that you can't refactor out the common code.

@steveklabnik steveklabnik added the A-lifetimes Area: Lifetimes / regions label Sep 29, 2015
@arielb1
Copy link
Contributor

arielb1 commented Sep 29, 2015

As this is equivalent to HKT, I am closing (feel free to open an RFC).

@arielb1 arielb1 closed this as completed Sep 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants