Skip to main content

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

TypeMinMax
i8-128127
i16-3276832767
i32-21474836482147483647
i64-92233720368547758089223372036854775807
u80255
u16065535
u3204294967295
u64018446744073709551615