rust-lang / rust-lang/rust

`concat!` does not respect integer literals' types

Open
#160,671 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

concat!(1234u8) constructs the string literal without checking whether the value is out-of-bounds for the given integer type.

Seems related to #115423.

I tried this code:

fn main() {
    let s = concat!(999999999u8);
    println!("{s}");
}

I expected to see this happen: error: literal out of range for u8

Instead, this happened: Prints 999999999, no error

Meta

rustc --version --verbose:

rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: aarch64-apple-darwin
release: 1.97.1
LLVM version: 22.1.6

(also occurs on Rust playground)


Notably, stringify! also doesn't error out; however, this seems expected, since stringify! deals with tokens rather than actual values (unlike concat!).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the concat!(999999999u8) example with the Rust compiler and inspect how concat! handles typed integer literals. Compare the behavior with the related issue #115423. Done means out-of-range integer literals passed to concat! produce the expected u8 range error rather than being emitted as a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.