You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
macro_rules! t {($item: literal) => {stringify!($item)}}fnmain(){println!("{}",t!(-1));}
The macro system recognizes -1 as a single literal in this case.
Instead, this happened:
error: expected a literal
--> src/main.rs:2:28
|
2 | println!("{}", concat!(-1));
| ^^
|
= note: only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()`
error: could not compile `playground` due to previous error
Meta
rustc --version --verbose:
Tried on playground, all channels:
Stable 1.66.1
Beta 1.67.0-beta.7 (2023-01-11 275123c)
Nightly 1.68.0-nightly (2023-01-13 0b90256)
Backtrace
The text was updated successfully, but these errors were encountered:
…r=dtolnay
allow negative numeric literals in `concat!`
Fixesrust-lang#106837
While *technically* negative numeric literals are implemented as unary operations, users can reasonably expect that negative literals are treated the same as positive literals.
I tried this code:
I expected to see this happen: code compiles.
Since the following code compiles:
The macro system recognizes
-1
as a single literal in this case.Instead, this happened:
Meta
rustc --version --verbose
:Tried on playground, all channels:
Stable 1.66.1
Beta 1.67.0-beta.7 (2023-01-11 275123c)
Nightly 1.68.0-nightly (2023-01-13 0b90256)
Backtrace
The text was updated successfully, but these errors were encountered: