False positive in keyword_idents_2024 · Issue #124862 · rust-lang/rust (original) (raw)

#![warn(keyword_idents_2024)]

#[allow(unused)] macro_rules! foo { ($gen:expr) => { $gen }; }

results in a warning

warning: `gen` is a keyword in the 2024 edition
 --> src/main.rs:5:7
  |
5 |     ($gen:expr) => {
  |       ^^^ help: you can use a raw identifier to stay compatible: `r#gen`
  |
  = warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024!
  = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(keyword_idents_2024)]
  |         ^^^^^^^^^^^^^^^^^^^

warning: `gen` is a keyword in the 2024 edition
 --> src/main.rs:6:10
  |
6 |         $gen
  |          ^^^ help: you can use a raw identifier to stay compatible: `r#gen`
  |
  = warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024!
  = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

The suggested code does compile (to my surprise), but the warning is a false positive. Switching the edition to 2024 results in a successful compilation as written. This is consistent with all other keywords that can be used as matchers, so I can't imagine this isn't intended behavior.

rustc info:

rustc 1.80.0-nightly (7d83a4c13 2024-05-06)
binary: rustc
commit-hash: 7d83a4c131ab9ae81a74c6fd825c827d74a2881d
commit-date: 2024-05-06
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4