rust-lang / rust-lang/rust-clippy
Add lints IMPLICIT_SATURATING_MUL and IMPLICIT_SATURATING_DIV
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Add lint similar to IMPLICIT_SATURATING_SUB and IMPLICIT_SATURATING_ADD, but for MUL and DIV.
Lint Name
IMPLICIT_SATURATING_MUL and IMPLICIT_SATURATING_DIV
Category
pedantic
Advantage
As mentioned at clippy::implicit_saturating_sub and clippy::implicit_saturating_add, the built-in function is more readable and may be faster.
Drawbacks
No response
Example
let mut i: u32 = 3;
i *= 2;
let mut i: u32 = 6;
i /= 2;
Could be written as:
let mut i: u32 = 3;
i = i.saturating_mul(2);
let mut i: u32 = 6;
i = i.saturating_div(2);
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 by reading the existing IMPLICIT_SATURATING_SUB and IMPLICIT_SATURATING_ADD lints and their surrounding tests, then compare how multiplication and division cases should be recognized. Done means IMPLICIT_SATURATING_MUL and IMPLICIT_SATURATING_DIV are available in the pedantic category and the provided examples produce the intended diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100