Skip to content

concat!() rejects negative number literal #106837

Closed
@johnmave126

Description

@johnmave126

I tried this code:

fn main() {
    println!("{}", concat!(-1));
}

I expected to see this happen: code compiles.

Since the following code compiles:

macro_rules! t {
    ($item: literal) => { stringify!($item) }
}

fn main() {
    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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions