-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lint overflowing integer casts in const prop #67676
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
5 commits
Select commit
Hold shift + click to select a range
e083273
Lint overflowing integer casts in const prop
wesleywiser 397a2fd
[const-prop] Extract some functions out of `_const_prop`
wesleywiser 1886985
[const-prop] Clean up `check_cast()` a bit
wesleywiser 001cea4
[const-prop] Expand comment about casting ZST enums
wesleywiser e8c1c4c
Ignore overflow lint on 32-bit platform
wesleywiser 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,49 @@ | ||
fn main() { | ||
let x = 42u8 as u32; | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let y = 42u32 as u8; | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.ConstProp.before.mir | ||
// let mut _0: (); | ||
// let _1: u32; | ||
// scope 1 { | ||
// debug x => _1; | ||
// let _2: u8; | ||
// scope 2 { | ||
// debug y => _2; | ||
// } | ||
// } | ||
// bb0: { | ||
// StorageLive(_1); | ||
// _1 = const 42u8 as u32 (Misc); | ||
// StorageLive(_2); | ||
// _2 = const 42u32 as u8 (Misc); | ||
// _0 = (); | ||
// StorageDead(_2); | ||
// StorageDead(_1); | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.before.mir | ||
// START rustc.main.ConstProp.after.mir | ||
// let mut _0: (); | ||
// let _1: u32; | ||
// scope 1 { | ||
// debug x => _1; | ||
// let _2: u8; | ||
// scope 2 { | ||
// debug y => _2; | ||
// } | ||
// } | ||
// bb0: { | ||
// StorageLive(_1); | ||
// _1 = const 42u32; | ||
// StorageLive(_2); | ||
// _2 = const 42u8; | ||
// _0 = (); | ||
// StorageDead(_2); | ||
// StorageDead(_1); | ||
// return; | ||
// } | ||
// END rustc.main.ConstProp.after.mir |
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,9 @@ | ||
// build-fail | ||
// ignore-tidy-linelength | ||
|
||
fn main() { | ||
let _ = 0u8 as u32; | ||
let _ = (1u32 << 31) as u16; //~ ERROR truncating cast: the value 2147483648 requires 32 bits but the target type is only 16 bits | ||
let _ = (1u16 << 15) as u8; //~ ERROR truncating cast: the value 32768 requires 16 bits but the target type is only 8 bits | ||
let _ = (!0u16) as u8; //~ ERROR truncating cast: the value 65535 requires 16 bits but the target type is only 8 bits | ||
} |
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,22 @@ | ||
error: truncating cast: the value 2147483648 requires 32 bits but the target type is only 16 bits | ||
--> $DIR/const-prop-overflowing-casts.rs:6:13 | ||
| | ||
LL | let _ = (1u32 << 31) as u16; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: truncating cast: the value 32768 requires 16 bits but the target type is only 8 bits | ||
--> $DIR/const-prop-overflowing-casts.rs:7:13 | ||
| | ||
LL | let _ = (1u16 << 15) as u8; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: truncating cast: the value 65535 requires 16 bits but the target type is only 8 bits | ||
--> $DIR/const-prop-overflowing-casts.rs:8:13 | ||
| | ||
LL | let _ = (!0u16) as u8; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
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
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.