rust-lang / rust-lang/rust-analyzer

Failure to parse macro converting a `stmt` into a `block`

Open
#11,770 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer version: 5e8515870 2022-03-14 stable

rustc version: rustc 1.59.0 (9d1b2106e 2022-02-23)

relevant settings: don't think I have anything custom

More or less minimal example:

fn main() {
    macro_rules! parse {
        ($action:block) => ($action);

        ($action:stmt) => (
            parse!({ $action })
        );
    }

    parse!(let _ = 1);
}

rust-analyzer errors with "expected Block", meanwhile rustc expands this fine into:

fn main() {
    {
        let _ = 1;
    };
}

Adding ; manually, i.e. parse!({ $action; }), makes r-a parse/expand it correctly but produces an "unnecessary trailing semicolon" warning.

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 minimal macro_rules! parse! reproducer in the issue and compare rust-analyzer's result with rustc's shown expansion. Done means the stmt-to-block case parses and expands without the erroneous "expected Block" error, while the workaround's unnecessary trailing-semicolon warning is not required.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.