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

Bounds in Higher-Ranked Lifetimes in trait objects don't seem to work #23051

Closed
arielb1 opened this issue Mar 5, 2015 · 3 comments
Closed

Bounds in Higher-Ranked Lifetimes in trait objects don't seem to work #23051

arielb1 opened this issue Mar 5, 2015 · 3 comments
Labels
A-trait-system Area: Trait system A-type-system Area: Type system

Comments

@arielb1
Copy link
Contributor

arielb1 commented Mar 5, 2015

use std::marker::CovariantLifetime as CLT;
fn does_not_compile<'b>(y: CLT<'b>) -> Box<for<'s:'b> Fn() -> CLT<'s>> {
    Box::new(move ||y)
}
fn does_compile<'b, 's:'b>(y: CLT<'b>) -> Box<Fn() -> CLT<'s>> {
    Box::new(move ||y)
}
fn main() {}

Error:

<anon>:3:21: 3:22 error: mismatched types:
 expected `core::marker::CovariantLifetime<'s>`,
    found `core::marker::CovariantLifetime<'b>`
(lifetime mismatch) [E0308]
<anon>:3     Box::new(move ||y)
                             ^
<anon>:3:21: 3:22 note: the lifetime 's as defined on the block at 3:20...
<anon>:3     Box::new(move ||y)
                             ^
<anon>:2:72: 4:2 note: ...does not necessarily outlive the lifetime 'b as defined on the block at 2:71
<anon>:2 fn does_not_compile<'b>(y: CLT<'b>) -> Box<for<'s:'b> Fn() -> CLT<'s>> {
<anon>:3     Box::new(move ||y)
<anon>:4 }
error: aborting due to previous error
playpen: application terminated with error code 101
@arielb1 arielb1 changed the title Bounds in HIgher-Ranked Lifetimes in trait objects don't seem to work Bounds in Higher-Ranked Lifetimes in trait objects don't seem to work Mar 5, 2015
@theemathas
Copy link
Contributor

Possibly releated to #22791

@kmcallister kmcallister added A-trait-system Area: Trait system A-type-system Area: Type system labels Mar 5, 2015
@steveklabnik
Copy link
Member

Triage: I am not sure how to reproduce this, as PhantomData is the replacement for the old *Lifetime types, and I am terrible with remembering the various variances. @arielb1 any idea about this today?

@Mark-Simulacrum
Copy link
Member

I can't reproduce this failure today, but it might be due to a lack of understanding how to do it with PhantomData. I'm going to give this a close since I think it's no longer relevant, but please do reopen with a modern example if possible. What I came up with is below, but it doesn't work.

use std::marker::PhantomData;

fn does_not_compile<'b>(y: PhantomData<&'b ()>) -> Box<for<'s: 'b> Fn() -> PhantomData<&'s ()>> {
    Box::new(move ||y)
}
fn does_compile<'b, 's:'b>(y: PhantomData<&'b ()>) -> Box<Fn() -> PhantomData<&'s ()>> {
    Box::new(move ||y)
}
fn main() {}
error[E0582]: binding for associated type `Output` references lifetime `'s`, which does not appear in the trait input types
 --> test.rs:3:76
  |
3 | fn does_not_compile<'b>(y: PhantomData<&'b ()>) -> Box<for<'s: 'b> Fn() -> PhantomData<&'s ()>> {
  |                                                                            ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

5 participants