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

Lifetimes get replaced with 'static in Self within (return position) impl Trait. #53613

Open
eddyb opened this Issue Aug 22, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@eddyb
Copy link
Member

eddyb commented Aug 22, 2018

#[derive(Copy, Clone)]
struct Invariant<'a>(std::marker::PhantomData<&'a mut &'a ()>);

impl<'a> Invariant<'a> {
    fn lazy_dup(self) -> impl Fn() -> (Invariant<'a>, Self) {
        || (self, self)
    }
}
error[E0308]: mismatched types
 --> src/lib.rs:6:19
  |
6 |         || (self, self)
  |                   ^^^^ lifetime mismatch
  |
  = note: expected type `Invariant<'static>`
             found type `Invariant<'a>`

I didn't write 'static anywhere - it comes from part of the implementation of impl Trait, and Self references lifetimes (from the impl header) "indirectly", hiding them from impl Trait logic.

cc @cramertj @oli-obk @nikomatsakis

@eddyb eddyb added the A-impl-trait label Aug 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment