rust-lang / rust-lang/rust-clippy
don't trigger `indexing_slicing` if the vector is infallible
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
there's many cases where a vector is clearly infallible but the indexing_slicing lint still complains that it might fall. Would be nice if clippy better recognize cases that are deterministically known to be infallible
Lint Name
indexing_slicing
Reproducer
I tried this code:
fn main() {
let vec = vec();
dbg!(vec[1]);
}
fn vec() -> Vec<i32> {
vec![0, 0, 0]
}
I saw this happen:
indexing may panic
consider using `.get(n)` or `.get_mut(n)` instead
for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#indexing_slicing
requested on the command line with `-W clippy::indexing-slicing
I expected to see this happen:
silence
Version
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8
Additional Labels
No response
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 with the indexing_slicing lint and run the provided Rust reproducer to observe the current warning. The change is done when indexing a vector whose bounds are deterministically safe is silent, while potentially panicking indexing continues to be reported.
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
- 45/100