.agents/skills/rust-code-quality/SKILL.md
Use this skill on every Rust code change to enforce quality rules that cargo clippy does not catch.
.rs files.Use these searches to find candidates in changed .rs files. Inspect syntax,
#[cfg(test)] scope, and the changed hunk before reporting a finding; text
filters do not reliably distinguish production code from tests.
# 1. unwrap/expect candidates
rg -n '\.unwrap\(\)|\.expect\(' <changed-files>
# 2. Silent type truncation via `as` cast
rg -n ' as (u8|u16|u32|u64|usize|i8|i16|i32|i64|isize)\b' <changed-files>
# 3. String as error type
rg -n 'Result<.*String>' <changed-files>
# 4. Box<dyn Error> in public APIs
rg -n 'Box<dyn.*Error' <changed-files>
# 5. println/eprintln in production
rg -n 'println!\|eprintln!' <changed-files>
# 6. Ordering::Relaxed usage (verify each is intentional)
rg -n 'Ordering::Relaxed' <changed-files>
# 7. Default substituted for a possibly-required value (judge each: is the value optional by domain?)
rg -n 'unwrap_or_default\(\)|unwrap_or\(' <changed-files>
For every Rust code change, verify:
unwrap() or expect() is infallible by type or a checked invariant; explain only non-obvious invariants, using an existing type, a useful expect message, or a concise commentResult<_, String> in public API signaturesError::source() is overridden when inner error is storedas truncation (negative→unsigned, large→small)TryFrom/try_into() and return a typed error; clamp or saturate only when the domain explicitly requires ittokio::sync lock guard (read or write) held across .await without bounded hold time — long-lived read guards wedge writers (#4195)fetch_* operation when possible; use compare_exchange only for conditional updatesstd::sync::Mutex in async context is held only briefly, never across .awaitBytes/Arc, or capacity reservation only when it reduces that cost without obscuring ownership or APIs#[should_panic], snapshot/property checks, and meaningful Result failures do not need a redundant assert!expect only when its message improves failure diagnosis; do not add boilerplate to self-evident test setup#[serde(deny_unknown_fields)]#[serde(default)] not used on security-critical fields without validation#![allow(dead_code)] at crate rootcrates/utils, crates/common, the touched crate, the likely domain-owning crate, a relevant direct dependency, or plain std/tokio behavior; reused helpers match the call site's semanticsSAFETY, durability, compatibility, and unwrap invariants## Rust Code Quality Report
### Automated Scan
- unwrap/expect candidates inspected: N
- numeric-cast candidates inspected: N
- error-type candidates inspected: N
- output-macro candidates inspected: N
### Findings
- [P1] `path:line` — description
- Fix: ...
- Validation: ...
### Verdict
PASS / BLOCKED (list blocking findings)