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;

Remediation

Widen the declared type to one that holds the value (u16, u32, i64), or correct the literal to the intended in-range constant. Where the bound is meant to be the type’s own limit, write u8::MAX instead of repeating the number.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved