rust-lang / rust-lang/rust-analyzer
Leftover tokens error in valid macro defining macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
The code snippet for reproduction below contains a macro that rust-analyzer complains with leftover tokens about, specifically line 15, at [x, y].
The code compiles with cargo build, so the macro is valid. Using cargo expand results in:
#![feature(prelude_import)]
#[macro_use]
extern crate std;
#[prelude_import]
use std::prelude::rust_2024::*;
struct X {
x: f64,
}
pub fn test() {
let a = X { x: 0.0 };
let u1 = 0.0;
let u1 = 0.0;
}
as expected.
rust-analyzer doesn't complain if sep_let is called only with $($d:tt $var:ident),*s of the same length. So it doesn't complain for
sep_let!(($x, $y) => let u1: [x, y]);
sep_let!(($x, $y) => let u1: [x, y]);
rust-analyzer version: 0.3.2660-standalone
rustc version: rustc 1.90.0 (1159e78c4 2025-09-14)
editor or extension: VSCode rust-analyzer extension v0.3.2660
relevant settings: probably none
code snippet to reproduce:
macro_rules! sep_let {
(($($d:tt $var:ident),*) => let $name:ident : [$($vals:tt)*] $(,)?) => {
macro_rules! __mac {
($($d $var:ident),*) => { 0.0 };
}
let $name = __mac!($($vals)*);
};
}
struct X { x: f64 }
pub fn test() {
let a = X { x: 0.0 };
sep_let!(($x, $y) => let u1: [x, y]);
sep_let!(($x) => let u1: [x]);
}
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
Start with the provided sep_let! reproduction and confirm the leftover tokens diagnostic at [x, y] while cargo build succeeds. Compare rust-analyzer's behavior with the shown cargo expand output and verify the diagnostic is absent for valid macro invocations of different lengths. Done means the valid macro no longer receives this false error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100