rust-lang / rust-lang/rust-analyzer

Expand macro output doesn't match actual output when forwarding `meta`

Open
#17,351 1 comment 0 reactions 0 assignees View on GitHub

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

When working with meta in macros, expand command may show wrong output.

macro_rules! meta_bug {
    (#[$m:meta]) => {
        meta_bug! { @inner $m }
    };
    
    (@inner test) => { 0 };
    (@inner $i:tt) => { 1 };
}

const RES: usize = meta_bug! { #[test] };
const _: () = assert!(RES == 1);

Unexpectedly, this example compiles, so RES is 1. But when expanding meta_bug! { #[test] } with rust-analyzer, it shows 0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided macro_rules! reproducer and compare rust-analyzer's expand command output with the stable Rust compiler result. Trace how the forwarded meta fragment is matched during macro expansion; done means rust-analyzer reports 1 for meta_bug! { #[test] }, matching compilation.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.