Closed
Description
Code
println("{}", 0xffff_ffff_u8);
// Simplest case
std::io::stdout().write_fmt(format_args!("{}\n", 0xffff_ffff_u8));
Current output
No error, program compiles and prints `4294967295`
Desired output
overflowing_literals lint should be triggered and program should not compile.
Rationale and extra context
No response
Other cases
// Changing anything will lead to an overflowing_literals error as expected:
println!("{:?}", 0xffff_ffff_u8); // error, doesn't compile
println!("{:x}", 0xffff_ffff_u8); // error
println!("{:>30}", 0xffff_ffff_u8); // error
let x = 0xffff_ffff_u8; println!("{x}"); // error
Anything else?
Error occurs on stable (1.73) and nightly (1.75.0 2023-10-09)
Clippy catches this error correctly, but not rustc itself.
I had a look at the HIR output and the bug seems to occur when the literal is compile-time formatted to a static str. This erases its type and prevents type checking.
Also, this is my first issue, so please let me know if any changes are desired.