Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overflowing_literals error not triggered in format_args for integer literal with default formatting #116631

Closed
tstsrt opened this issue Oct 11, 2023 · 4 comments · Fixed by #123935
Assignees
Labels
A-fmt Area: std::fmt A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tstsrt
Copy link
Contributor

tstsrt commented Oct 11, 2023

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.

@tstsrt tstsrt added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 11, 2023
@agluszak
Copy link

@rustbot claim

@jdahlstrom
Copy link

jdahlstrom commented Oct 11, 2023

Probably a regression caused by the recent change that bakes literals straight into the format string.

agluszak added a commit to agluszak/rust that referenced this issue Oct 11, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 11, 2023
Do not inline integer linterals which are out of range in format_args!

Inlining integers (even those out of range) was introduced in rust-lang#106824.

Closes rust-lang#116631.
@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. A-fmt Area: std::fmt regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed A-diagnostics Area: Messages for errors, warnings, and lints needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 11, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 11, 2023
@lukas-code
Copy link
Member

This is a duplicate of #115423.

@apiraino
Copy link
Contributor

ok @lukas-code thanks! Closing as duplicate: also bisection of this issue and of #115423 lead to the same group of PRs.

@apiraino apiraino closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 11, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 18, 2024
Don't inline integer literals when they overflow - new attempt

Basically rust-lang#116633 but I implemented the suggested changes.
Fixes rust-lang#115423. Fixes rust-lang#116631.

This is my first contribution to this repo so please let me know if I'm supposed to change something :)
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Apr 18, 2024
Don't inline integer literals when they overflow - new attempt

Basically rust-lang#116633 but I implemented the suggested changes.
Fixes rust-lang#115423. Fixes rust-lang#116631.

This is my first contribution to this repo so please let me know if I'm supposed to change something :)
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Apr 19, 2024
Don't inline integer literals when they overflow - new attempt

Basically rust-lang#116633 but I implemented the suggested changes.
Fixes rust-lang#115423. Fixes rust-lang#116631.

This is my first contribution to this repo so please let me know if I'm supposed to change something :)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 19, 2024
Rollup merge of rust-lang#123935 - tstsrt:fix-115423, r=oli-obk

Don't inline integer literals when they overflow - new attempt

Basically rust-lang#116633 but I implemented the suggested changes.
Fixes rust-lang#115423. Fixes rust-lang#116631.

This is my first contribution to this repo so please let me know if I'm supposed to change something :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fmt Area: std::fmt A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
7 participants