Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vdrn opened this issue Mar 22, 2025 · 0 comments
Open

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

vdrn opened this issue Mar 22, 2025 · 0 comments
Labels
A-macro macro expansion C-bug Category: bug

Comments

@vdrn
Copy link

vdrn commented Mar 22, 2025

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)

@vdrn vdrn added the C-bug Category: bug label Mar 22, 2025
@ShoyuVanilla ShoyuVanilla added the A-macro macro expansion label Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants