Closed
Description
I tried this code:
fn main() {
let x: i32 = 0b1000_0000_0000_0000_0000_0000_0000_0000i32;
println!("{}", x);
}
I expected the code to compile since its i am assigning into x binary representation of i32::MIN, instead the compiler throws an error.
Meta
rustc --version --verbose
:
1.67.1
Backtrace
Compiling playground v0.0.1 (/playground)
error: literal out of range for `i32`
--> src/main.rs:2:18
|
2 | let x: i32 = 0b1000_0000_0000_0000_0000_0000_0000_0000i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the type `u32` instead: `0b1000_0000_0000_0000_0000_0000_0000_0000u32`
|
= note: the literal `0b1000_0000_0000_0000_0000_0000_0000_0000i32` (decimal `2147483648`) does not fit into the type `i32` and will become `-2147483648i32`
= note: `#[deny(overflowing_literals)]` on by default
error: could not compile `playground` due to previous error
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Call for participation: Help is requested to fix this issue.Relevant to the compiler team, which will review and decide on the PR/issue.