Do not inline integer literals which are out of range in format_args!#116633
Do not inline integer literals which are out of range in format_args!#116633agluszak wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
|
Technically that's a breaking change... |
|
Hm yeah. Nominating for T-lang, impl looks ok but I didn't look at it too long -- will do after T-lang confirms we should re-break this. In the mean time, I'll do a crater run. @bors try |
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.
|
☀️ Try build successful - checks-actions |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
| LitIntType::Signed(IntTy::I32) => i32::MAX as u128, | ||
| LitIntType::Signed(IntTy::I64) => i64::MAX as u128, | ||
| LitIntType::Signed(IntTy::I128) => i128::MAX as u128, | ||
| LitIntType::Signed(IntTy::Isize) => isize::MAX as u128, |
There was a problem hiding this comment.
This uses the host's isize, but should be using use the target's isize. Same for usize below.
There was a problem hiding this comment.
Fair. What should I do to obtain these values for the target?
There was a problem hiding this comment.
You can get size of isize and usize from tcx.data_layout.pointer_size. That will return a Size, which has the signed_int_max and unsigned_int_max methods that seem useful. It looks like the nearest tcx is the one in the LoweringContext, which you get as self from here:
| LitIntType::Unsigned(UintTy::U64) => u64::MAX as u128, | ||
| LitIntType::Unsigned(UintTy::U128) => u128::MAX, | ||
| LitIntType::Unsigned(UintTy::Usize) => usize::MAX as u128, | ||
| LitIntType::Unsuffixed => u128::MAX, |
There was a problem hiding this comment.
| LitIntType::Unsuffixed => u128::MAX, | |
| LitIntType::Unsuffixed => i32::MAX, |
Unsuffixed and unconstrained integer literals should have type i32, even if they overflow.
See the old behavior before inlining: https://rust.godbolt.org/z/PMG7ac4d4
| @@ -0,0 +1,3 @@ | |||
| fn main() { | |||
| format_args!("{}\n", 0xffff_ffff_u8); //~ ERROR literal out of range for `u8` | |||
There was a problem hiding this comment.
Should this have a test for each of the different integer types?
There was a problem hiding this comment.
At the very least it should have a test case that covers #115423 (which I don't interpet is about being out of range, but rather about not respecting the type of the literal).
|
According to the linked PR, it's meant to be gated behind Edit: ah that flag seems to have been stabilized to default to on, I didn't see that |
|
🎉 Experiment
|
|
We discussed this in the @rust-lang/lang triage meeting today. Everyone agreed that this was "just" a bug, and should be fixed. Printing a token that's explicitly marked an i8 and getting a result outside the range of an i8 is clearly wrong. Ideally this would trigger the overflowing_literals lint same as using a token like this as an expression in other places. |
|
@rustbot labels -I-lang-nominated |
|
Awaiting feedback above @rustbot author |
|
I'll fix it on Saturday or Sunday |
|
ping from triage - can you post your status on this PR? This PR has not received an update in a few months. Thank you! FYI: when a PR is ready for review, send a message containing |
|
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
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 :)
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 :)
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 :)
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 :)
Inlining integers (even those out of range) was introduced in #106824.
Closes #116631.
Closes #115423.