Skip to content

rust.unsafe_block_unaudited

Correctness High

Detects unsafe blocks without safety documentation explaining why the code is sound.

Unaudited unsafe:

  • Hides undefined behavior — Easy to miss errors
  • Blocks code review — No safety reasoning documented
  • Causes memory bugs — Use-after-free, data races
// ❌ Before (undocumented unsafe)
unsafe {
ptr::copy_nonoverlapping(src, dst, len);
}
// ✅ After (documented safety invariants)
// SAFETY: `src` and `dst` are valid for `len` bytes,
// properly aligned, and non-overlapping.
// This is ensured by the allocation in `new()`.
unsafe {
ptr::copy_nonoverlapping(src, dst, len);
}
  • Unsafe blocks without SAFETY comments
  • Unsafe fn implementations without docs
  • Missing invariant documentation

Unfault adds a SAFETY comment template for you to fill in.