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

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

Existential types have issues with lifetimes #62988

jethrogb opened this issue Jul 25, 2019 · 0 comments

Comments

@jethrogb
Copy link
Contributor

@jethrogb jethrogb 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

RalfJung added a commit to RalfJung/rust that referenced this issue Jun 11, 2020
…=nikomatsakis

Clean up type alias impl trait implementation

- Removes special case for top-level impl trait
- Removes associated opaque types
- Forbid lifetime elision in let position impl trait. This is consistent with the behavior for inferred types.
- Handle lifetimes in type alias impl trait more uniformly with other parameters

cc rust-lang#69323
cc rust-lang#63063
Closes rust-lang#57188
Closes rust-lang#62988
Closes rust-lang#69136
@bors bors closed this in ce6d3a7 Jun 15, 2020
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 23, 2020
…ikomatsakis

Clean up type alias impl trait implementation

- Removes special case for top-level impl trait
- Removes associated opaque types
- Forbid lifetime elision in let position impl trait. This is consistent with the behavior for inferred types.
- Handle lifetimes in type alias impl trait more uniformly with other parameters

cc rust-lang#69323
cc rust-lang#63063
Closes rust-lang#57188
Closes rust-lang#62988
Closes rust-lang#69136
Closes rust-lang#73061
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants