rust-lang / rust-lang/rust-clippy
Checking for (integer) constants in lints is inconsistent and does not handle all cases (e.g., static constants)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Several lints such as the integer_arithmetic and modulo_one lint check for specific integer constants, typically +/-1, 0, MIN, MAX. However, this is currently implemented inconsistently, sometimes only checking for (+/-) literals (integer_arithmetic, see also #6209), sometimes also for constants (modulo_one). However, the modulo_one lint also fails to properly handle static constants (see also #6360); I am not sure, if this is due to some deeper reason I don't yet understand or if this is simply a bug.
I would suggest consolidating these checks for particular values to rely on a single constant-comparison function similar to (or replacing) the is_integer_const function, but also handling static constants. Likely, this could be used in other places as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with clippy_lints/src/utils/mod.rs and the is_integer_const function, then compare how the integer_arithmetic and modulo_one lints detect integer constants. Reproduce the static-constant case described alongside #6360 and review #6209. Done means the affected lints use consistent constant checks that also handle static constants.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100