Skip to content

Existential type captures lifetime that doesn't appear in bounds even though it does appear #57188

Closed
@Palladinium

Description

@Palladinium
#![feature(existential_type)]

struct Baz<'a> {
    source: &'a str,
}

trait Foo<'a> {
    type T: Iterator<Item = Baz<'a>> + 'a;
    fn foo(source: &'a str) -> Self::T;
}

struct Bar;
impl<'a> Foo<'a> for Bar {
    existential type T: Iterator<Item = Baz<'a>> + 'a;
    fn foo(source: &'a str) -> Self::T {
        std::iter::once(Baz { source })
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
  --> src/lib.rs:15:5
   |
15 |     existential type T: Iterator<Item = Baz<'a>> + 'a;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: hidden type `std::iter::Once<Baz<'a>>` captures the lifetime 'a as defined on the impl at 14:6
  --> src/lib.rs:14:6
   |
14 | impl<'a> Foo<'a> for Bar {
   |      ^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

May be related to #42940, but I'm not entirely sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemF-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions