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 · Fixed by #72080
Closed

Existential types have issues with lifetimes #62988

jethrogb opened this issue Jul 25, 2019 · 0 comments · Fixed by #72080
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jethrogb
Copy link
Contributor

#![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

@rustbot rustbot added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. labels Jul 25, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
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 as completed 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
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

Successfully merging a pull request may close this issue.

3 participants