rust-lang / rust-lang/rust-clippy
Potential improvement to reversed_empty_ranges
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
While it is stated that this lint cannot catch loops over dynamically defined ranges, it could be improved to catch the following common pattern:
let x = 5u32;
for i in x..0 { ... }
Note that it is a range over unsigned values, so it makes no sense for the right side to be zero (as the range will always be empty then). Similar check could be done for signed integers by iXXX::MIN const.
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 reversed_empty_ranges lint and its tests. Check how ranges over unsigned values are analyzed, then determine how the lint should recognize a nonzero start with a zero upper bound and the analogous signed-integer minimum case. Done means the patterns are diagnosed and covered by tests.
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
- 42/100