rust-lang / rust-lang/rust-analyzer
Expanding macro gives wrong result when trying to "specialize" metavariables
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Consider the following macro:
macro_rules! what_number {
($num:literal) => {
what_number!(@inner $num)
};
(@inner 42) => {
"the answer to everything"
};
(@inner $num:literal) => {
stringify!($num)
};
}
fn main() {
let result = what_number!(42);
println!("{result}");
}
The compiler expands what_number!(42) to "42", but RA shows "the answer to everything".
See here for an explanation of why "42" should be the correct result.
rust-analyzer version: rust-analyzer version: 0.0.0 (427061da1 2022-06-19)
rustc version: rustc 1.63.0-nightly (ca122c7eb 2022-06-13)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the macro example from the issue in rust-analyzer and compare its expansion with rustc, focusing on the recursive what_number! rules and metavariable matching. Done means rust-analyzer reports or displays the same result as rustc: "42" rather than "the answer to everything".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100