Skip to content

Braces are removed from single-item import in macro where they are required #6047

Open
@junbl

Description

@junbl

In a macro that takes a path as an argument:

macro_rules! get_msg {
    ($module:path) => {
        let message = {
            use $module::{MESSAGE}; // note the (usually unnecessary) brackets
            MESSAGE
        };
        println!("{}", message);
    };
}

The braces around MESSAGE are required, and the code fails to compile without them. However, rustfmt removes them.

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ca5ee49a37c35354f67d82d6303c7f5a

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-macrosbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions