Closed
Description
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
Activity
konnorandrews commentedon Sep 1, 2023
I went and looked through the
format_args!()
implementation and found where the issue comes from. The check at https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast_lowering/src/format.rs#L131 ignores the integer type, and it blindly callsn.string()
on theu128
value of the literal.gurry commentedon Sep 3, 2023
@rustbot claim
apiraino commentedon Sep 7, 2023
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
overflowing_literals
error not triggered informat_args
for integer literal with default formatting #11663114 remaining items