-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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>());
}
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
precise_capturing
syntax rust-lang/rust#123432Veykril commentedon Jul 15, 2024
Given we dont really handle opaque types wrt to their generic captures fully anyways I reckon it ought to be enough for us to merely add the parsing here for starters which is a simple change (ah thats what the issue is mainly asking for anyways whoops)
Veykril commentedon Jul 15, 2024
Needs a corresponding grammar rule in https://github.com/rust-lang/rust-analyzer/blob/master/crates/syntax/rust.ungram
Then run
cargo codegen grammar
and finally edit the parser hererust-analyzer/crates/parser/src/grammar/generic_params.rs
Lines 141 to 186 in e9afba5
If new inline parser tests were added you can then run
cargo codegen inline-parser-tests
to regenerate thosewinstxnhdw commentedon Jul 16, 2024
I’ll give this a go :)
+ use<..>
precise_capturing
syntax #17676Auto merge of #17676 - winstxnhdw:precise-capturing, r=Veykril
Auto merge of rust-lang#127672 - compiler-errors:precise-capturing, r…
Auto merge of rust-lang#127672 - compiler-errors:precise-capturing, r…
Auto merge of #127672 - compiler-errors:precise-capturing, r=spastorino