Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::decimal_literal_representation: Warns if there is a better representation for a numeric literal
What it meansWarns if there is a better representation for a numeric literal. It is in the restriction group and off by default.
Does it matter?
Especially for big powers of 2, a hexadecimal representation is usually more readable than a decimal representation.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
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:
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
decimal_literal_representation = "warn"In code
#![warn(clippy::decimal_literal_representation)]One run
cargo clippy -- -W clippy::decimal-literal-representationThe [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.
Settings in clippy.toml
literal-representation-threshold: The lower bound for linting decimal literals
Clippy's own documentation
What it does
Warns if there is a better representation for a numeric literal.
Why restrict this?
Especially for big powers of 2, a hexadecimal representation is usually more readable than a decimal representation.
Example
`255` => `0xFF`
`65_535` => `0xFFFF`
`4_042_322_160` => `0xF0F0_F0F0`
Configuration
-
literal-representation-threshold: The lower bound for linting decimal literals(default:
16384)
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- cognitive_complexityWe used to think it measured how hard a method is to understand
- create_dircalling `std::fs::create_dir` where there may be a better way
- dbg_macroChecks for usage of the dbg! macro
- default_numeric_fallbackdefault numeric fallback might occur
- default_union_representationthis union has the default representation
- definition_in_module_rootChecks for definitions (structs, functions, traits, etc.) in mod.rs files
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?