E0044: Integer Literal Out of Range
An integer literal does not fit in the type it was resolved to.
Example
fn main() {
let x: i8 = 300; // Error: integer literal `300` does not fit in type `i8`
}
fn main() {
let y: u8 = -1; // Error: integer literal `-1` does not fit in type `u8`
}
How to fix
Either use a literal value that fits within the target type's range, or use a wider type:
fn main() {
let x: i8 = 100; // OK: 100 fits in i8 (-128..127)
let y: i16 = 300; // OK: 300 fits in i16 (-32768..32767)
let z: u8 = 255; // OK: 255 fits in u8 (0..255)
}
Integer type ranges
| Type | Min | Max |
|---|---|---|
i8 | -128 | 127 |
i16 | -32768 | 32767 |
i32 | -2147483648 | 2147483647 |
i64 | -9223372036854775808 | 9223372036854775807 |
u8 | 0 | 255 |
u16 | 0 | 65535 |
u32 | 0 | 4294967295 |
u64 | 0 | 18446744073709551615 |