-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
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)