Skip to content

Suboptimal interaction between lifetime oriented and value oriented type system in the presence of closures. #125250

Open
@gl-yziquel

Description

@gl-yziquel

This code compiles with the comments and does not compile without the comments.

fn main() {
    fn subparsing_lifetime<'s, 'r>(args: &'s Vec<&'s str>) -> (&'r ()/*, &'s ()*/) { unreachable!() }
    let closure = |args| subparsing_lifetime(&args);
}

It runs in the compiler error "cannot return value referencing function parameter".

This highlights, to me, suboptimal interaction between the lifetime oriented type system and the value oriented type system.

The typing guarantees that the function parameter is not referenced in the values.

Moreover, there are use cases, bumpalo arenas, for instance, where it is perfectly legitimate to have lifetimes shared between arguments and returned values, with no dependencies between one and the other.

So this code should compile if uncommented.

One of the interest I have in rust is precisely the ability to share lifetimes between independent references.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-langRelevant to the language teamT-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