E0800: Literal out of range
| Code | Category | Stability |
|---|---|---|
E0800 | Literal and operator | Permanent |
Explanation
An integer literal must denote a value representable in the type it is given. Rue takes that type from the surrounding annotation, parameter, return position, struct field, match scrutinee, or constant declaration and range-checks the literal against it, so an out-of-range value is rejected rather than silently truncated or wrapped. The deliberate exception is a negated literal that denotes a signed type's minimum, such as -128 for i8. Comptime evaluation applies the same check to a non-negative computed result that does not fit its target type. Float literals are governed by their own finite-value rule and do not report this code.
Likely cause
An annotation, field type, parameter, scrutinee, or constant is narrower than the literal written for it, as in let small: u8 = 300; or const BAD: u8 = 300;. Widen the target type, or write a value inside its range. An unannotated literal takes its type from its uses, so a wrong or missing annotation is the usual source.
Examples
Assign a literal too large for its type
fn main() -> i32 {
let small: u8 = 300;
0
}
Widen the annotated type
fn main() -> i32 {
let small: u16 = 300;
@intCast(small)
}