Description
When a proc-macro generates code, and the opening brace of a pattern from that code comes from the input, then the compiler thinks that the pattern is a 2024 pattern, and thus enforces the new pattern rules using the local edition, not the edition from the proc-macro.
There are two consequences:
- This is incompatible with supporting macros that are on different editions.
- It generates an invalid suggestion.
Example of the bad suggestion might be:
#[derive(my_macro)]
struct S {
f1: i32
}
will give a suggestion to modify the struct to add an &
which is invalid syntax like this:
struct &S {
f1: i32
}
This was seen with swc_macros_common here where it uses the brace token from the input.
One option is to change this in the macro to generate a new token with the correct span information.
I'm also wondering if there are options for changing the ways tokens are processed from proc-macros to avoid this altogether.
Meta
rustc --version --verbose
:
rustc 1.84.0-nightly (81eef2d36 2024-11-11)
binary: rustc
commit-hash: 81eef2d362a6f03db6f8928f82d94298d31eb81b
commit-date: 2024-11-11
host: aarch64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3