dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.9k stars 311 forks source link

Deny keyword lifetimes pre-expansion #1708

Open dtolnay opened 4 months ago

dtolnay commented 4 months ago

As of nightly-2024-07-18, rustc has begin rejecting code such as the following, which used to parse successfully. https://github.com/rust-lang/rust/pull/126762

#[cfg(any())]
fn f<'ref>() {}
error: lifetimes cannot use keyword names
 --> src/main.rs:2:6
  |
2 | fn f<'ref>() {}
  |      ^^^^

If this is no longer valid Rust syntax, syn should reject it too.

dtolnay commented 1 month ago

Rustc still allows keyword lifetimes in macro input, so the Parse impl for syn::Lifetime probably needs to continue to allow them too.

fn main() {
    println!("{}", stringify!('ref));
}

But syntax tree uses of Lifetime, such as in GenericParam, can begin rejecting these.