Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

T10 Deny indexing/arithmetic/as_conversions

Question

The three bug classes ADR 7 removes at compile time: indexing_slicing (v[i] → v.get(i).ok_or(...)?), arithmetic_side_effects (+/* → checked_*/saturating_*), as_conversions (narrowing as → TryFrom).

This is the largest and most pervasive ticket, because TUI layout math (as_conversions on u16/usize rects, arithmetic on areas) and collector slicing. Likely splits per crate, record the split in the first run rather than guessing now.

Exit predicate

The three classes denied in [workspace.lints.clippy], cargo clippy --workspace green. Any remaining exception is a scoped #[allow] carrying a reason a reviewer can see, never a bare suppression.

Resolution

Done 2026-11-09. indexing_slicing, arithmetic_side_effects and as_conversions are denied in [workspace.lints.clippy]; cargo clippy --workspace --all-targets is clean without a single suppression of these three classes outside two sanctioned mechanisms: clippy.toml’s allow-indexing-slicing-in-tests (already in place since T02) and the cucumber harness’s file-level allow (extended with the two new classes; step functions are test code whose panic IS the failure signal, same reason as T09’s).

The predicted per-crate split was not needed; the predicted geography was wrong. The ticket feared the TUI; reality: ~169 unique sites, in three passes. Measurement lesson: a first clippy pass reported only core’s 14 sites, because core’s deny-errors stopped cargo from compiling the dependent crates at all. Real volumes per crate:

  • cerebro-core: 14 sites. Ten counter/line-number +1s → saturating_add; scanned - registered in unregistered_count → saturating_sub (a real underflow guard: config can register more than disk scans); the two length-check-then-index sites (journal.rs date parse, storage.rs::parse_remote_owner) → slice patterns and split_first, which make the length invariant structural instead of asserted.
  • cerebro-tui: 136 sites (89 arithmetic, 34 indexing, 13 as-conversions). Layout rects: layout[i] → .get(i).copied().unwrap_or_default() (an empty rect renders nothing; the invariant is the constraint count). Area math → saturating_add/sub/mul; percent math keeps the exact truncating semantics via saturating_mul(x) / 100 (division by a nonzero constant literal is not flagged; div_ceil sneaked into one edit and was reverted, because it changed the value). Nav wrap (i+1)%5 → saturating_add(1).rem_euclid(5); the spinner’s const-fn tick became a saturate-then-reset (slice get is not const-callable on the pinned nightly, so current_frame lost const). The 13 as conversions: widening u16→usize → usize::from; SummaryCard took usize at its API instead of callers casting; a test’s [] as [Rect; 0] → Vec::new().
  • cerebro (the command-line crate) and cerebro-tui/tests/cucumber.rs: 19 sites, surfaced only after tui compiled. DateTime - DateTime → signed_duration_since; DateTime/NaiveDate - Duration → checked_sub_signed/checked_add_signed (chrono’s operators expect on overflow, so this closes a panic the panic lint could not see).

Gate evidence: cargo clippy --workspace --all-targets -- -D warnings clean; just quality green (fmt, clippy, workspace tests, doctests, release suite 70 passed, cucumber, vale 0/0); cerebro status runs; cerebro build --fresh from the branch regenerated cortex (journal index.md, today.md, this-week.md re-stamped, day links and activity graph intact); the MCP server answered tools/list and read_journal for both the success path and the invalid-date error path of the rewritten parser.

Prose-gate catch: the CI pipeline pins vale 3.17.1 while this machine runs 3.26.0, and the green local just quality hid findings the pinned version makes (spaced em-dashes, prose abbreviations, the repo vocab missing chrono). The docs pipeline on the pull request caught what the local gate could not; fixed by clearing the style hits and adding [Cc]hrono to .vale/styles/Cerebro/Vocab.yml. The toolchain pin discipline (T01) applies to the prose gate too. The local vale version is not the gate.