Long numeric literal written without digit separators
ID |
rust.maintainability.unreadable_literal |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Readability |
Language |
Rust |
Description
Detects a numeric literal long enough to be hard to read that does not use the _ digit separator: six or more decimal digits, or nine or more digits in a hexadecimal, binary or octal literal.
Rationale
Rust allows _ anywhere inside a numeric literal precisely because an unbroken run of digits cannot be checked by eye. A reviewer cannot tell 1000000 from 10000000, so an off-by-one-order-of-magnitude constant - a timeout, a byte limit, a bit mask - passes review unnoticed and only shows up as a production incident.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Long numeric literal written without digit separators
pub const MAX_BYTES: usize = 100000;