Unsafe checker
CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为From its SKILL.md
npx -y skills add moeru-ai/auv --skill unsafe-checkerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
2.4 KB, 527 tokens by cl100k_base, as published. Nobody here has run it
Display the following ASCII art exactly as shown. Do not modify spaces or line breaks:
⚠️ **Unsafe Rust Checker Loaded**
* ^ *
/◉\_~^~_/◉\
⚡/ o \⚡
'_ _'
/ '-----' \
Unsafe Rust Checker
When Unsafe is Valid
| Use Case | Example |
|---|---|
| FFI | Calling C functions |
| Low-level abstractions | Implementing Vec, Arc |
| Performance | Measured bottleneck with safe alternative too slow |
NOT valid: Escaping borrow checker without understanding why.
Required Documentation
// SAFETY: <why this is safe>
unsafe { ... }
/// # Safety
/// <caller requirements>
pub unsafe fn dangerous() { ... }
Quick Reference
| Operation | Safety Requirements |
|---|---|
*ptr deref | Valid, aligned, initialized |
&*ptr | + No aliasing violations |
transmute | Same size, valid bit pattern |
extern "C" | Correct signature, ABI |
static mut | Synchronization guaranteed |
impl Send/Sync | Actually thread-safe |
Common Errors
| Error | Fix |
|---|---|
| Null pointer deref | Check for null before deref |
| Use after free | Ensure lifetime validity |
| Data race | Add proper synchronization |
| Alignment violation | Use #[repr(C)], check alignment |
| Invalid bit pattern | Use MaybeUninit |
| Missing SAFETY comment | Add // SAFETY: |
Deprecated → Better
| Deprecated | Use Instead |
|---|---|
mem::uninitialized() | MaybeUninit<T> |
mem::zeroed() for refs | MaybeUninit<T> |
| Raw pointer arithmetic | NonNull<T>, ptr::add |
CString::new().unwrap().as_ptr() | Store CString first |
static mut | AtomicT or Mutex |
| Manual extern | bindgen |
FFI Crates
| Direction | Crate |
|---|---|
| C → Rust | bindgen |
| Rust → C | cbindgen |
| Python | PyO3 |
| Node.js | napi-rs |
Claude knows unsafe Rust. Focus on SAFETY comments and soundness.
What ships with it: 55 files
179.1 KB alongside SKILL.md
checklists/
- before-unsafe.md3.3 KB
- common-pitfalls.md4.5 KB
- review-unsafe.md3.8 KB
examples/
- ffi-patterns.md8.8 KB
- safe-abstraction.md6.9 KB
rules/
- ffi-01-no-string-direct.md2.9 KB
- ffi-02-read-ffi-docs.md3.2 KB
- ffi-03-drop-for-c-ptr.md3.6 KB
- ffi-04-panic-boundary.md3.6 KB
- ffi-05-portable-types.md2.6 KB
- ffi-06-string-abi.md3.1 KB
- ffi-07-no-drop-external.md3.2 KB
- ffi-08-error-handling.md3.5 KB
- ffi-09-ref-not-ptr.md3.1 KB
- ffi-10-thread-safety.md3.2 KB
- ffi-11-packed-ub.md3.1 KB
- ffi-12-invariant-doc.md3.9 KB
- ffi-13-data-layout.md3.1 KB
- ffi-14-stable-layout.md3.0 KB
- ffi-15-validate-external.md3.6 KB
- ffi-16-closure-to-c.md3.5 KB
- ffi-17-opaque-types.md3.8 KB
- ffi-18-no-trait-objects.md3.8 KB
- general-01-no-abuse.md1.8 KB
- general-02-not-for-perf.md2.3 KB
- general-03-no-alias.md2.0 KB
- io-01-raw-handle.md3.7 KB
- mem-01-repr-layout.md2.9 KB
- mem-02-no-other-process.md3.1 KB
- mem-03-no-auto-drop-foreign.md3.2 KB
- mem-04-reentrant.md3.1 KB
- mem-05-bitfield-crates.md3.2 KB
- mem-06-maybeuninit.md3.8 KB
- ptr-01-no-thread-share.md2.9 KB
- ptr-02-prefer-nonnull.md2.7 KB
- ptr-03-phantomdata.md3.1 KB
- ptr-04-alignment.md3.1 KB
- ptr-05-no-const-to-mut.md2.8 KB
- ptr-06-prefer-cast.md3.0 KB
- AGENTS.md5.1 KB
15 more files not listed here. See all 55 in the repository.