Skip to content

format_args! does not respect integer literals' type #115423

Closed
@endorpersand

Description

@endorpersand

When using the 1234i8 syntax in the Display format in formatting macros, the i8 is ignored and treated as a u128.

I tried this code:

fn main() {
    println!("{}", 0x8Fi8);
}

I expected to see this happen: Getting an error that 0x8F is out of the bounds for type i8.

Instead, this happened: This function compiles and prints 143.

Meta

rustc --version --verbose:

rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-apple-darwin
release: 1.71.1
LLVM version: 16.0.5

Metadata

Metadata

Assignees

Labels

A-fmtArea: `core::fmt`C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions