Skip to content

Support for + use<..> precise_capturing syntax #17598

Closed
@traviscross

Description

We're planning to stabilize #![feature(precise_capturing)] ahead of Rust 2024 (in all editions). This feature allows one to write:

fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                  ~~~~~~~~~~~~~~~~~~~~~~~
//                          This opaque type does not capture `'a`.

fn outlives<'o, T: 'o>(_: T) {}

fn caller<'o, 'a, 'b: 'o, T: 'o>() {
    //        ~~
    //        ^ Note that we don't need `'a: 'o`.
    outlives::<'o>(captures::<'a, 'b, T>());
}

Playground link

That is, it allows for the precise capturing of generic parameters in RPIT-like impl Trait opaque types (the initial stabilization will require all in scope type and const parameters to be included in the use<..> bound; see the stabilization report for other restrictions). We need this to stabilize so that we can stabilize the Lifetime Capture Rules 2024 (RFC 3498) in Rust 2024. These are lang team priority items for the Rust 2024 edition.

Currently r-a gives errors about this syntax:

fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                              ~   ~~ ~  ~ ^ Syntax Error: expected an item
//                                              |   |  |  ^ Syntax Error: expected BANG
//                                              |   |  |  ^ Syntax Error: expected `{`, `[`, `(`
//                                              |   |  ^ Syntax Error: expected an item
//                                              |   ^ Syntax Error: expected SEMICOLON
//                                              ^ Syntax Error: expected a block

The earliest this syntax could conceivably stabilize is with Rust 1.82, which will branch on 2024-08-30 and will be released on 2024-10-17.

Tracking:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-parserparser issuesA-tytype system / type inference / traits / method resolutionC-featureCategory: feature requestE-easyE-has-instructionsIssue has some instructions and pointers to code to get started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions