Skip to content

Putting braces around match arm with macro call and trait resolution breaks parser #74302

@matprec

Description

@matprec

I tried this code:

struct X;

macro_rules! foo {
    () => (X);
}

fn foo(a: u32) {
    let _: Option<X> = match a {
        // This obviously works
        0 => X.into(),
        // This works as well
        1 => foo!{}.into(),
        // This does not
        _ => {
            foo!{}.into()
        },
    };
}

I expected to see this happen: The code for the default match arm parses successfully just like the others.

Instead, this happened: It errors for the default match arm, because of the braces. This happens on every stable and nightly i've tested. This is a minimal reproducer from a program using quote, which gets constantly broken because rustfmt tries to format the actually longer line into a block.

Meta

Playground stable, nightly

rustc --version --verbose:

rustc 1.45.0-nightly (7ced01a73 2020-04-30)
binary: rustc
commit-hash: 7ced01a730e8fc1bae2f8d4369c26812c0484da4
commit-date: 2020-04-30
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions