Rules / TAU-P003

No panicking index or slice

decided by Clippy kernel deny core deny edge warn
Applies to tests: no Exceptions: #[expect] + reason

Why

v[i] and &s[a..b] panic on out-of-range or non-char-boundary input; off-by-one errors become crashes.

Fix

Use .get(i) / .get(a..b) and handle None, iterate instead of indexing, or use split_at_checked. In a kernel crate this is a proof obligation: a recorded proof that the function never fails discharges it (cargo tauten obligations).

What it checks

Lints: clippy::indexing_slicing, clippy::string_slice

Seen in fixtures

rej-dependent/src/lib.rs core

//! Depends on a crate with violations; has its own. /// First port.#[must_use]pub fn first(v: &[&str]) -> u16 {    rej_unwrap::port(v[0])}

$ cargo tauten check

error[TAU-P003]: indexing may panic  --> rej-dependent/src/lib.rs:6:22 (core crate `rej-dependent`)  = rule: No panicking index or slice (decided by Clippy)  = fix: Use `.get(i)` / `.get(a..b)` and handle None, iterate instead of indexing, or use `split_at_checked`. In a kernel crate this is a proof obligation: a recorded proof that the function never fails discharges it (`cargo tauten obligations`).
Fixture rej-dependent (core) expects TAU-P003. Output captured at 0200db3.

rej-index/src/lib.rs core

//! Panicking index. /// First byte.#[must_use]pub fn first(v: &[u8]) -> u8 {    v[0]}

$ cargo tauten check

error[TAU-P003]: indexing may panic  --> rej-index/src/lib.rs:6:5 (core crate `rej-index`)  = rule: No panicking index or slice (decided by Clippy)  = fix: Use `.get(i)` / `.get(a..b)` and handle None, iterate instead of indexing, or use `split_at_checked`. In a kernel crate this is a proof obligation: a recorded proof that the function never fails discharges it (`cargo tauten obligations`).
Fixture rej-index (core) expects TAU-P003. Output captured at 0200db3.

In the terminal

cargo tauten explain TAU-P003

$ cargo tauten explain TAU-P003

TAU-P003: No panicking index or slice Why: `v[i]` and `&s[a..b]` panic on out-of-range or non-char-boundary input; off-by-one errors become crashes. Fix: Use `.get(i)` / `.get(a..b)` and handle None, iterate instead of indexing, or use `split_at_checked`. In a kernel crate this is a proof obligation: a recorded proof that the function never fails discharges it (`cargo tauten obligations`). Decided by: ClippyDecides: No panicking index or string slice in linted code.Sees: resolved; complete: yesDoes not see: Code expanded from macros defined in other crates (clippy skips it); code disabled by `cfg`; build scripts.Applies to tests: noExceptions allowed: with #[expect(.., reason)]  kernel deny  core deny  edge warnLints: clippy::indexing_slicing, clippy::string_slice