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

Existential types have issues with lifetimes #62988

Open
jethrogb opened this issue Jul 25, 2019 · 0 comments

Comments

@jethrogb
Copy link
Contributor

commented Jul 25, 2019

#![feature(existential_type)]

trait MyTrait {
    type AssocType: Send;
    fn ret(&self) -> Self::AssocType;
}

impl MyTrait for () {
    existential type AssocType: Send;
    fn ret(&self) -> Self::AssocType {
        ()
    }
}

impl<'a> MyTrait for &'a () {
    existential type AssocType: Send;
    fn ret(&self) -> Self::AssocType {
        ()
    }
}

trait MyLifetimeTrait<'a> {
    type AssocType: Send + 'a;
    fn ret(&self) -> Self::AssocType;
}

impl<'a> MyLifetimeTrait<'a> for &'a () {
    existential type AssocType: Send + 'a;
    fn ret(&self) -> Self::AssocType {
        *self
    }
}
error: could not find defining uses
  --> src/lib.rs:16:5
   |
16 |     existential type AssocType: Send;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
  --> src/lib.rs:28:5
   |
28 |     existential type AssocType: Send + 'a;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: hidden type `&'a ()` captures the lifetime 'a as defined on the impl at 27:6
  --> src/lib.rs:27:6
   |
27 | impl<'a> MyLifetimeTrait<'a> for &'a () {
   |      ^^

error: could not find defining uses
  --> src/lib.rs:28:5
   |
28 |     existential type AssocType: Send + 'a;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

cc @cramertj

(original report at #34511 (comment))

@rustbot modify labels: A-impl-trait C-bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.