syn icon indicating copy to clipboard operation
syn copied to clipboard

Deny keyword lifetimes pre-expansion

Open dtolnay opened this issue 1 year ago • 1 comments

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 avatar Jul 17 '24 21:07 dtolnay

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.

dtolnay avatar Oct 24 '24 05:10 dtolnay