Skip to content

Macro expansion involving identifiers in parentheses preceded by visibility is broken #15537

Open
@kontheocharis

Description

@kontheocharis

The following snippet does not expand the macro foo! correctly:

fn main() {}

macro_rules! foo {
    ($a:vis ($b:ident)) => {
        pub const X: &str = stringify!($b);
    };
}

foo!(
    pub (bar)
);

Instead of expanding to

pub const X: &str = "bar"

it expands to

pub const X: &str = "$ b"

It seems that rust-analyzer puts a space between the $ and the b before substituting the macro variables, resulting in a wrong expansion. rustc handles this expansion correctly.

rust-analyzer version: rust-analyzer version: 0.3.1641-standalone (144526c 2023-08-28) [I have also tried rust-analyzer version: 0.4.1644-standalone (3213344 2023-08-30)]
rustc version: rustc 1.74.0-nightly (84a9f4c6e 2023-08-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionA-parserparser issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions