-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.Performance or correctness regression from one stable version to another.
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.
Metadata
Metadata
Assignees
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant 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.Performance or correctness regression from one stable version to another.