Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive in keyword_idents_2024 #124862

Closed
jhpratt opened this issue May 7, 2024 · 7 comments · Fixed by #124869
Closed

False positive in keyword_idents_2024 #124862

jhpratt opened this issue May 7, 2024 · 7 comments · Fixed by #124869
Assignees
Labels
A-edition-2024 Area: The 2024 edition A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. C-future-incompatibility Category: Future-incompatibility lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-gen_blocks `gen {}` expressions that produce `Iterator`s

Comments

@jhpratt
Copy link
Member

jhpratt commented May 7, 2024

#![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
@jhpratt jhpratt added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. A-edition-2024 Area: The 2024 edition F-gen_blocks `gen {}` expressions that produce `Iterator`s labels May 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 7, 2024
@jhpratt jhpratt removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 7, 2024
@compiler-errors
Copy link
Member

This was preexisting in the lint (fires for $async too in ed 2015), but perhaps more likely to be encountered with the $gen fragment matcher. I can fix it.

@compiler-errors compiler-errors self-assigned this May 7, 2024
@jhpratt
Copy link
Member Author

jhpratt commented May 7, 2024

I was just looking into it myself. I think it's a two line fix? Copying what's done for dyn seems like it should work. Though now that I say that, I'm not sure, as it might mean code in the expansion rather than the definition.

https://github.com/rust-lang/rust/pull/123680/files#diff-f16097779719dd3638857eefc5ee3eb5052f3d1921df2c672153601aa5f5242fR1906

@compiler-errors
Copy link
Member

@jhpratt:

That's too heavy of a hammer, and will cause this test to not fail even though it should:

#![deny(keyword_idents_2024)]

macro_rules! t {
    () => { fn gen() {} }
}

t!();

@compiler-errors
Copy link
Member

We should specifically be detecting macro vars that have keyword names instead.

@compiler-errors compiler-errors removed their assignment May 7, 2024
@compiler-errors
Copy link
Member

But if you're looking into it already, be my guest. Just make sure to claim it next time :)

@jhpratt
Copy link
Member Author

jhpratt commented May 7, 2024

Nah, go ahead! I merely saw the PR that added the lint and noticed something that might have been of interest.

@compiler-errors
Copy link
Member

Alright then 👍 I'll reclaim

@compiler-errors compiler-errors self-assigned this May 7, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 8, 2024
Make sure we don't deny macro vars w keyword names

`$async:ident`, etc are all valid.

Fixes rust-lang#124862
@bors bors closed this as completed in 952f12e May 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 8, 2024
Rollup merge of rust-lang#124869 - compiler-errors:keyword, r=Nilstrieb

Make sure we don't deny macro vars w keyword names

`$async:ident`, etc are all valid.

Fixes rust-lang#124862
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. C-future-incompatibility Category: Future-incompatibility lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-gen_blocks `gen {}` expressions that produce `Iterator`s
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants