Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.runtime

Prefer fallible slice access for variable indices

Direct indexing with a variable can panic when the index is out of bounds.

#Metadata

Rule ID
rust.correctness.unchecked-index
Severity
medium
Confidence
0.8
Languages
rust
Presets
strict
Stability
stable
Applies to
block
Tags
correctness, rules-catalog, rust

#Why it matters

Slice indexing with a non-literal index panics on bounds failure. Use `.get(index)` when the index comes from a variable and handle `None` explicitly.

#Remediation

Replace direct indexing with `.get(index)` and handle the `None` case.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/rust/rust.correctness.unchecked-index.rule.yaml.