Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tracking issue for existential lifetimes #60670

Copy link
Copy link
@alexreg

Description

@alexreg
Issue body actions

This is a tracking issue for existential lifetimes.

Description:

Allow hiding a type (via impl Trait) that is invariant over some lifetime without explicitly mentioning the invariant lifetime.

Consider the following:

impl Trait<'b> for Cell<&'a u32> { }

fn foo(x: Cell<&'x u32>) -> impl Trait<'y> where 'x: 'y { x }

There is no reason this cannot be legal, although it is not permitted at present. We would want to translate the function signature internally into something like:

fn foo(x: Cell<&'x u32>) -> impl exists<'x: 'y> Trait<'y> where 'x: 'y { x }

Although it be noted there is no need for user-facing exists<...> syntax; only HIR and ty representations probably. The concrete type corresponding to impl exists<'x: 'y> Trait<'y> can this be soundly checked by the compiler at use site.

Note, we still need to be careful to ban situations like those mentioned by @matthewjasper in #59402. By actually embedding the existential lifetime in the type rather than simply doing a check when resolving the opaque type, we should be able to resolve these issues, however. One can view this solution as a "compiler-internalised" version of the Captures marker trait solution, in some sense.

Steps:

CC @Centril @nikomatsakis @matthewjasper @cramertj

dima74, MOZGIII and rubik

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemT-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant 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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.