keyword-idents is incompatible with macros #133709
Labels
A-edition-2024
Area: The 2024 edition
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-bug
Category: This is a bug.
D-edition
Diagnostics: An error or lint that should account for edition differences.
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
I-edition-triaged
Issue: This issue has been reviewed and triaged by the Edition team.
L-keyword_idents
Lint group: keyword_idents
L-keyword_idents_2024
Lint: keyword_idents_2024
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The
keyword_idents
lint has incorrect suggestions in macro_rules macros (there are potentially separate concerns for the definition versus invocation). It suggests changing a new keyword to the raw identifier, but this is a semantic change (see #49520).LHS Definition
Consider:
This suggests changing it to a raw identifier:
However, this is a semantic change because macro_rules does not treat an equivalence between raw and normal identifiers (or keywords). Thus, another crate using this macro:
will fail with the error "no rules expected
gen
", or "no rules expected reserved keywordgen
" in 2024.Invocation
Perhaps more difficult to resolve is the rewrites for an invocation.
Let's say we have a crate (any edition), with something like:
and then I am trying to migrate my crate to 2024:
This will suggest to change it to
a::other_macro!(r#gen)
, which is incorrect because that does not match any matchers.I say this is more difficult, because there are some situations where changing the invocation is the correct thing to do. Consider:
and trying to migrate another crate to 2024:
this gives the correct suggestion to rewrite it to
a::other_macro!(let r#gen = 1);
, which would fail to compile if it wasn't changed.Possible solutions
There are different angles to tackle this problem:
The latter seems like a bigger can of worms.
For the former, some rough thoughts:
Meta
The text was updated successfully, but these errors were encountered: