-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't inline integer literals when they overflow - new attempt #123935
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ only-64bit | ||
|
||
fn main() { | ||
format_args!("{}", 0x8f_i8); // issue #115423 | ||
//~^ ERROR literal out of range for `i8` | ||
format_args!("{}", 0xffff_ffff_u8); // issue #116633 | ||
//~^ ERROR literal out of range for `u8` | ||
format_args!("{}", 0xffff_ffff_ffff_ffff_ffff_usize); | ||
//~^ ERROR literal out of range for `usize` | ||
format_args!("{}", 0x8000_0000_0000_0000_isize); | ||
//~^ ERROR literal out of range for `isize` | ||
format_args!("{}", 0xffff_ffff); // treat unsuffixed literals as i32 | ||
//~^ ERROR literal out of range for `i32` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
error: literal out of range for `i8` | ||
--> $DIR/no-inline-literals-out-of-range.rs:4:24 | ||
| | ||
LL | format_args!("{}", 0x8f_i8); // issue #115423 | ||
| ^^^^^^^ | ||
| | ||
= note: the literal `0x8f_i8` (decimal `143`) does not fit into the type `i8` and will become `-113i8` | ||
= note: `#[deny(overflowing_literals)]` on by default | ||
help: consider using the type `u8` instead | ||
| | ||
LL | format_args!("{}", 0x8f_u8); // issue #115423 | ||
| ~~~~~~~ | ||
help: to use as a negative number (decimal `-113`), consider using the type `u8` for the literal and cast it to `i8` | ||
| | ||
LL | format_args!("{}", 0x8f_u8 as i8); // issue #115423 | ||
| ~~~~~~~~~~~~~ | ||
|
||
error: literal out of range for `u8` | ||
--> $DIR/no-inline-literals-out-of-range.rs:6:24 | ||
| | ||
LL | format_args!("{}", 0xffff_ffff_u8); // issue #116633 | ||
| ^^^^^^^^^^^^^^ help: consider using the type `u32` instead: `0xffff_ffff_u32` | ||
| | ||
= note: the literal `0xffff_ffff_u8` (decimal `4294967295`) does not fit into the type `u8` and will become `255u8` | ||
|
||
error: literal out of range for `usize` | ||
--> $DIR/no-inline-literals-out-of-range.rs:8:24 | ||
| | ||
LL | format_args!("{}", 0xffff_ffff_ffff_ffff_ffff_usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the literal `0xffff_ffff_ffff_ffff_ffff_usize` (decimal `1208925819614629174706175`) does not fit into the type `usize` and will become `18446744073709551615usize` | ||
|
||
error: literal out of range for `isize` | ||
--> $DIR/no-inline-literals-out-of-range.rs:10:24 | ||
| | ||
LL | format_args!("{}", 0x8000_0000_0000_0000_isize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the literal `0x8000_0000_0000_0000_isize` (decimal `9223372036854775808`) does not fit into the type `isize` and will become `-9223372036854775808isize` | ||
|
||
error: literal out of range for `i32` | ||
--> $DIR/no-inline-literals-out-of-range.rs:12:24 | ||
| | ||
LL | format_args!("{}", 0xffff_ffff); // treat unsuffixed literals as i32 | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: the literal `0xffff_ffff` (decimal `4294967295`) does not fit into the type `i32` and will become `-1i32` | ||
= help: consider using the type `u32` instead | ||
help: to use as a negative number (decimal `-1`), consider using the type `u32` for the literal and cast it to `i32` | ||
| | ||
LL | format_args!("{}", 0xffff_ffffu32 as i32); // treat unsuffixed literals as i32 | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 5 previous errors | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.