Skip to content

concat!() rejects negative number literal #106837

Closed

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

Activity

  1. Ezrashaw commented on Jan 14, 2023

    @Ezrashaw
    Contributor

    Hmm, this actually looks like fun to fix.

    @rustbot claim

  2. added 2 commits that reference this issue on Mar 11, 2023
    c243ea3
    d47d4ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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