rust-lang / rust-lang/rust-clippy

reversed_empty_ranges false positive

Open
#5,808 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.