rust-lang / rust-lang/rust-analyzer

macro-error expected leaf: `;` when using a macro

Open
#10,151 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I'm seeing an error message on a macro expansion in rust-analyzer expected leaf: ; rust-analyzer(macro-error). I can run and build the crate fine. Removing the generic parameters on the macro resolves the error.

The macro is building a enum definiton as well as implementing parsing traits based on the macro arguments.

I created https://github.com/semicoleon/macro-error-demo with a (mostly) minimal example of a macro that causes the error. The README has slightly more information about the error as well as the cargo expand output.

I encountered this in rust-analyzer d15f646ff 2021-08-30 stable on macOS. I also tried building from source rust-analyzer c16e6474f 2021-09-04 dev and also encountered the issue there.

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 mostly minimal reproducer in the linked macro-error-demo repository, read its README, and compare the reported diagnostic with the cargo expand output. Trace how rust-analyzer handles the macro's generic parameters and generated enum and parsing traits; done means the false expected leaf: ; diagnostic no longer appears while the crate still builds.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.