Clippy lints / Style
Clippy lint · Style · checked with Clippy 0.1.99
clippy::inconsistent_digit_grouping: digits grouped inconsistently by underscores
What it meansWarns if an integral or floating-point constant is grouped inconsistently with underscores. It is in the style group and warns by default.
What you see
warning: digits grouped inconsistently by underscores --> main.rs:3:1 | 3 | 618_64_9189_73_511 | ^^^^^^^^^^^^^^^^^^ help: consider: `61_864_918_973_511` | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#inconsistent_digit_grouping = note: `#[warn(clippy::inconsistent_digit_grouping)]` on by default
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Readers may incorrectly interpret inconsistently grouped digits.
Code that works but is not idiomatic Rust. Warns by default.
How to fix it
Clippy does not fix this one automatically (its suggestion may change behaviour, so it only shows it). Change the code by hand:
Flagged
618_64_9189_73_511
Write this instead
61_864_918_973_511
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::inconsistent_digit_grouping)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
inconsistent_digit_grouping = "allow"One run
cargo clippy -- -A clippy::inconsistent-digit-groupingThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Warns if an integral or floating-point constant is grouped inconsistently with underscores.
Why is this bad?
Readers may incorrectly interpret inconsistently grouped digits.
Example
618_64_9189_73_511
Use instead:
61_864_918_973_511
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- needless_returnunneeded `return` statement
- new_without_defaultChecks for public types with a pub fn new() -> Self method and no implementation of Default
- len_zeroChecks for getting the length of something via .len() just to compare to zero, and suggests using .is_empty() where applicable
- if_same_then_elseChecks for if/else with the same body as the then part and the else part
- implicit_saturating_addmanual saturating add detected
- implicit_saturating_subChecks for implicit saturating subtraction
- infallible_destructuring_matchyou seem to be trying to use `match` to destructure a single infallible pattern
- inherent_to_stringimplementation of inherent method `to_string(&self) -> String` for type `main::A`
- init_numbered_fieldsused a field initializer for a tuple struct
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::needless_returnunneeded `return` statementRead it next →Did this answer your question?