Rules / TAU-U002

Documented, minimal unsafe blocks

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

Why

Each unsafe operation needs its own stated justification for review.

Fix

Split blocks to one unsafe operation each and add a // SAFETY: comment explaining why the contract holds.

What it checks

Lints: clippy::undocumented_unsafe_blocks, clippy::multiple_unsafe_ops_per_block

Seen in fixtures

rej-undocumented-unsafe/src/lib.rs edge

//! An unsafe block without a safety comment. /// The first byte of a non-empty slice.#[must_use]pub fn first(bytes: &[u8]) -> Option<u8> {    if bytes.is_empty() {        return None;    }    Some(unsafe { *bytes.get_unchecked(0) })}

$ cargo tauten check

error[TAU-U002]: unsafe block missing a safety comment  --> rej-undocumented-unsafe/src/lib.rs:9:10 (edge crate `rej-undocumented-unsafe`)  = rule: Documented, minimal unsafe blocks (decided by Clippy)  = fix: Split blocks to one unsafe operation each and add a `// SAFETY:` comment explaining why the contract holds.
Fixture rej-undocumented-unsafe (edge) expects TAU-U002. Output captured at 0200db3.

In the terminal

cargo tauten explain TAU-U002

$ cargo tauten explain TAU-U002

TAU-U002: Documented, minimal unsafe blocks Why: Each unsafe operation needs its own stated justification for review. Fix: Split blocks to one unsafe operation each and add a `// SAFETY:` comment explaining why the contract holds. Decided by: ClippyDecides: Every `unsafe` block in the edge has a `SAFETY:` comment and one unsafe operation.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: yesExceptions allowed: with #[expect(.., reason)]  kernel -  core -  edge denyLints: clippy::undocumented_unsafe_blocks, clippy::multiple_unsafe_ops_per_block