rust-lang / rust-lang/rust-clippy
reversed_empty_ranges false positive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
As a user of ndarray, I can use negative indexing in slices, like I would do with NumPy
// A view of the image without borders
let block = image.slice(s![1..-1, 1..-1, 1..-1]);
Since Rust 1.45.0, I get this error when I run clippy: error: this range is empty so it will yield no values. This message is wrong: my code compiles and runs as intended. Clippy shouldn't only check if end <= start, it should also check if end is negative, or if it's a isize slice.
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 locating the reversed_empty_ranges lint and reproduce the reported snippet with ndarray-style negative indexing. Done means valid negative or isize slices no longer trigger the false positive, while genuinely empty ranges still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100