Literal is outside the range of the declared integer type
ID |
rust.correctness.overflowing_literals |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Numeric Literal |
Language |
Rust |
Description
Detects let, const and static declarations with an explicit 8-, 16- or 32-bit integer type whose initialiser literal falls outside that type’s range, such as let x: u8 = 300;.
Rationale
The value the code appears to state is not the value the type can hold, so either the type or the constant is wrong. The mismatch is usually a copied limit that was never adjusted when the field width changed, and it turns into a truncated or rejected constant.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Literal is outside the range of the declared integer type
const RETRY_LIMIT: u8 = 300;