rust-lang / rust-lang/rust-clippy
out_of_bounds_indexing false positive
Open
Nobody has claimed this yet.
C-bug
E-hard
T-middle
T-MIR
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
This comes from a code reduction, so it's reasonable in its original context:
#![allow(unused_variables)]
fn main() {
const N: usize = 1_000;
let data = [0, 0, 0, 0];
if N <= 4 {
let result = data[N - 1];
}
}
error: index out of bounds: the len is 4 but the index is 999
--> src/main.rs:6:22
|
6 | let result = data[N - 1];
| ^^^^^^^^^^^
|
= note: #[deny(const_err)] on by default
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
Reproduce the Rust snippet in src/main.rs using the Rust nightly setup referenced in the issue, then trace the out_of_bounds_indexing diagnostic. Done means the guarded access in the example no longer produces the reported false-positive error, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100