rust-lang / rust-lang/rust-analyzer
Invalid macro error persists after restart
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: 1.88.0-nightly (0fe8f345 2025-04-10)
rustc version: 1.88.0-nigtly (0fe8f345 2025-04-10)
editor or extension: Zed
relevant settings: N/A
repository link (if public, optional): /
code snippet to reproduce:
macro_rules! example {
(
$(#[$attr:meta])*
$visibility:vis enum $name:ident {
$(
$(#[$variant_attr:meta])*
#($message:expr)
$variant_name:ident $( ( $($variant_type:ty),* ) )?
),*
}
) => {
$(#[$attr])*
$visibility enum $name {
$(
$(#[$variant_attr])*
$variant_name $((
$($variant_type),*
))?,
)*
}
impl $name {
pub fn get_message(&self) -> &'static str {
match self {
$(
Self:: $variant_name $( ($(only_second!($variant_type | _))*) )? => $message
)*
}
}
}
};
}
macro_rules! only_second {
($first:tt | $second:tt) => {
$second
};
}
example! {
/// foo
pub enum A {
/// bar
#("Hello, world")
Variant(&'static str)
}
}
RA will display an error under &'static str in A::Variant:
unexpected token in input (rust-analyzer macro-error)
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 by reproducing the supplied macro_rules! example in rust-analyzer with Zed and confirm the unexpected token error under &'static str in A::Variant. Trace the macro expansion or parsing path involved in this nested repetition and token transformation. Done means the example no longer reports the macro-error after restarting the editor.
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
- 35/100