rust-lang / rust-lang/rust-analyzer
Macro parser did not remove fragment correctly
Open
Nobody has claimed this yet.
A-macro
C-bug
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer 1.88.0-nightly (a15cce2 2025-04-17)
rustc version: rustc 1.88.0-nightly (a15cce269 2025-04-17)
editor or extension: VIM-9.1
code snippet to reproduce:
use proc_macro_impl::remove_fragment;
macro_rules! foo {
(1+2) => {};
}
macro_rules! pack {
($e:expr) => {
remove_fragment!(foo!($e))
};
}
fn main() {
pack!(1+2);
}
use proc_macro::*;
#[proc_macro]
pub fn remove_fragment(stream: TokenStream) -> TokenStream {
stream.into_iter().map(|tt| {
match tt {
TokenTree::Group(g) => {
let mut out = Group::new(g.delimiter(), remove_fragment(g.stream()));
out.set_span(g.span());
out.into()
}
_ => tt,
}
}).collect()
}
cargo build 0 errors
rust-analyzer.expandMacro:
// Recursive expansion of pack!! macro
// ====================================
Expansion had errors:
expected literal: `1`
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 rust-analyzer.expandMacro entry point and the minimal Rust reproduction in the issue, comparing its output with the successful cargo build. Trace how remove_fragment! handles the 1+2 token fragment during recursive pack! expansion; done when the macro expands without the expected literal error.
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