rust-lang / rust-lang/rust-analyzer
"Leftover tokens" error in macro accepted by rustc
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.3.2761-standalone
rustc version: rustc 1.93.0 (254b59607 2026-01-19)
editor: VSCode 1.109.0
relevant settings: None I think
code snippet to reproduce:
Cargo.toml:
[package]
name = "ra_error"
version = "0.1.0"
edition = "2024"
[dependencies]
src/lib.rs:
macro_rules! repro {
(@_inner: $arg:tt ) => { $arg };
( $arg:ty ) => { repro!(@_inner: $arg ) }
}
// ra gives: "macro-error: leftover tokens" here
type Foo = repro!(Option<i32>);
rustc and clippy both accept this code without warning (except a warning about Foo being unused).
cargo-expand yields the expected output:
joe@laptop:/workspaces/ra_error:dev$ cargo expand
Checking ra_error v0.1.0 (/workspaces/ra_error)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.60s
#![feature(prelude_import)]
#[macro_use]
extern crate std;
#[prelude_import]
use std::prelude::rust_2024::*;
#[allow(dead_code)]
type Foo = Option<i32>;
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 Cargo.toml and src/lib.rs reproduction in rust-analyzer, comparing its result with rustc, clippy, and cargo-expand. Trace how the macro invocation is analyzed and verify that the valid type alias no longer produces a "leftover tokens" error while preserving expected diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100