rust-lang / rust-lang/rust-clippy

Potential improvement to reversed_empty_ranges

Open
#2,477 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.