dtolnay / dtolnay/proc-macro2

Edition 2024 reserved tokens are accepted

Open
#535 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
934
Forks
135
PR merge metrics
No merged PRs in 30d

Description

The 2024 edition reserved unprefixed guarded string literals and two or more `#` characters. However, proc-macro2 is parsing these with the previous edition behavior. I'm not sure what the edition policy of proc-macro2 is, but I would somewhat expect these to be rejected.

```rust
use std::str::FromStr;

fn main() {
for input in [
"#\"foo\"#",
"##",
] {
println!("{:?}", proc_macro2::TokenStream::from_str(input));
}
}
```

outputs:

```
Ok(TokenStream [Punct { char: '#', spacing: Alone }, Literal { lit: "foo" }, Punct { char: '#', spacing: Alone }])
Ok(TokenStream [Punct { char: '#', spacing: Joint }, Punct { char: '#', spacing: Alone }])
```

The edition chapter on the reservation: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/reserved-syntax.html. This is from [RFC 3593](https://github.com/rust-lang/rfcs/pull/3593). The grammar from the reference is:

```
RESERVED_GUARDED_STRING_LITERAL -> `#`+ STRING_LITERAL

RESERVED_POUNDS -> `#`{2..}
```

Using `proc-macro2 1.0.106`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.