Skip to content

impl Trait should be able to capture long-lived associated types even if the trait contains a lifetime #54385

Open
@RalfJung

Description

@RalfJung

Basically, this should compile:

trait Trait<'foo> { type Assoc: 'static; }

fn test<'foo, T: Trait<'foo>>(x: T::Assoc) -> impl FnOnce() {
    move || { let _x = x; }
}

Thanks to @eddyb I can work around this, writing

trait Trait<'foo> { type Assoc: 'static; }

fn test<'foo, A: 'static, T: Trait<'foo, Assoc=A>>(x: T::Assoc) -> impl FnOnce() {
    move || { let _x = x; }
}

but that is almost impossible to discover.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions