Clippy · Reliability
Indexing or slicing that can panic
clippy::indexing_slicing
Use get or get_mut and handle the absent element instead of indexing, which panics out of bounds.
- Category
- Reliability
- Default level
- off
- Tier
- P3
- Producer
- Clippy
- Diff scope
- line
Not a defect when
The index is provably in bounds from a length check or loop range just above, such as iterating 0..v.len(), and a panic there would signal a bug rather than bad input.
What it reads
Clippy, with the compiler behind it. The only pass that compiles.
Tier
Lowest tier: real, and rarely urgent.
The tier bounds how severe a rule may be; its category bounds the tier.Diff scope
The changed line itself.
What--scope contextual looks at to decide whether a change caused the finding.Change it
Turn it off, or make it blocking, without touching the code it flags:
rust-doctor --rule clippy::indexing_slicing=off .
rust-doctor --rule clippy::indexing_slicing=error .