Skip to content

RA macro expansion adds unwanted parenthesis to literal/expr #19418

@vdrn

Description

@vdrn

Below code compiles fine with rustc, but produces error diagnostic with RA.

macro_rules! test_macro {
    ($i:ident, $e:literal) => {
        pub const $i: &str = concat!($e);
    };
}

test_macro!(T1, 42.0); // fine
test_macro!(T2, -42.0); // error

Unlike rustc, RA macro expansion adds parentheses around negative numbers like -42.0:

test_macro!(T2, -42.0);

expands to

const T2: &str = concat!((-42.0));;

which produces diagnostic: expected a literal: only literals can be passed to concat!().

NOTE: even if RA did not add the parenthesis, there would still be a problem with concat!(-42.0). But that seem to be separate issue, which I filed here: #19417

rust-analyzer version: 1.87.0-nightly (be73c1f 2025-03-21)

rustc version: rustc 1.87.0-nightly (be73c1f46 2025-03-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions