rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

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

Open YaLTeR opened this issue 2 years ago • 3 comments

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.

YaLTeR avatar Mar 20 '22 08:03 YaLTeR

I can't reproduce it now. (3eb340fa4 2022-08-10)

Maybe it is fixed ?

edwin0cheng avatar Aug 11 '22 14:08 edwin0cheng

reproduces for me on 5366009fe 2022-08-09 image

Veykril avatar Aug 11 '22 15:08 Veykril

Oh , I forget to turn on the rust-analyzer.diagnostics.experimental.enable.

edwin0cheng avatar Aug 11 '22 15:08 edwin0cheng