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 绑定, 未定义行为
- License 许可
- MIT
- 最近更新
- 2026-04-11
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- unsafe-checker
- globs
- [ "**/*.rs" ]
- description
- 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 绑定, 未定义行为
- allowed-tools
- [ "Read", "Grep", "Glob" ]
02 资源文件 56
- 参考文档AGENTS.md5.1 KB
- 参考文档checklists/before-unsafe.md3.3 KB
- 参考文档checklists/common-pitfalls.md4.5 KB
- 参考文档checklists/review-unsafe.md3.8 KB
- 参考文档examples/ffi-patterns.md8.8 KB
- 参考文档examples/safe-abstraction.md6.9 KB
- 参考文档metadata.json685 B
- 参考文档rules/_sections.md1.9 KB
- 参考文档rules/_template.md765 B
- 参考文档rules/ffi-01-no-string-direct.md2.9 KB
- 参考文档rules/ffi-02-read-ffi-docs.md3.2 KB
- 参考文档rules/ffi-03-drop-for-c-ptr.md3.6 KB
- 参考文档rules/ffi-04-panic-boundary.md3.6 KB
- 参考文档rules/ffi-05-portable-types.md2.6 KB
- 参考文档rules/ffi-06-string-abi.md3.1 KB
- 参考文档rules/ffi-07-no-drop-external.md3.2 KB
- 参考文档rules/ffi-08-error-handling.md3.5 KB
- 参考文档rules/ffi-09-ref-not-ptr.md3.1 KB
- 参考文档rules/ffi-10-thread-safety.md3.2 KB
- 参考文档rules/ffi-11-packed-ub.md3.1 KB
- 参考文档rules/ffi-12-invariant-doc.md3.9 KB
- 参考文档rules/ffi-13-data-layout.md3.1 KB
- 参考文档rules/ffi-14-stable-layout.md3.0 KB
- 参考文档rules/ffi-15-validate-external.md3.6 KB
- 参考文档rules/ffi-16-closure-to-c.md3.5 KB
- 参考文档rules/ffi-17-opaque-types.md3.8 KB
- 参考文档rules/ffi-18-no-trait-objects.md3.8 KB
- 参考文档rules/general-01-no-abuse.md1.8 KB
- 参考文档rules/general-02-not-for-perf.md2.3 KB
- 参考文档rules/general-03-no-alias.md2.0 KB
- 参考文档rules/io-01-raw-handle.md3.7 KB
- 参考文档rules/mem-01-repr-layout.md2.9 KB
- 参考文档rules/mem-02-no-other-process.md3.1 KB
- 参考文档rules/mem-03-no-auto-drop-foreign.md3.2 KB
- 参考文档rules/mem-04-reentrant.md3.1 KB
- 参考文档rules/mem-05-bitfield-crates.md3.2 KB
- 参考文档rules/mem-06-maybeuninit.md3.8 KB
- 参考文档rules/ptr-01-no-thread-share.md2.9 KB
- 参考文档rules/ptr-02-prefer-nonnull.md2.7 KB
- 参考文档rules/ptr-03-phantomdata.md3.1 KB
- 参考文档rules/ptr-04-alignment.md3.1 KB
- 参考文档rules/ptr-05-no-const-to-mut.md2.8 KB
- 参考文档rules/ptr-06-prefer-cast.md3.0 KB
- 参考文档rules/safety-01-panic-safety.md2.9 KB
- 参考文档rules/safety-02-verify-invariants.md2.5 KB
- 参考文档rules/safety-03-no-uninit-api.md2.9 KB
- 参考文档rules/safety-04-double-free.md2.8 KB
- 参考文档rules/safety-05-send-sync.md2.9 KB
- 参考文档rules/safety-06-no-raw-ptr-api.md3.1 KB
- 参考文档rules/safety-07-unsafe-pair.md2.9 KB
- 参考文档rules/safety-08-no-mut-from-immut.md2.8 KB
- 参考文档rules/safety-09-safety-comment.md3.2 KB
- 参考文档rules/safety-10-safety-doc.md3.3 KB
- 参考文档rules/safety-11-assert-not-debug.md3.1 KB
- 参考文档rules/union-01-avoid-except-ffi.md2.6 KB
- 参考文档rules/union-02-no-cross-lifetime.md2.9 KB
03 SKILL.md 正文
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.
04 同仓库更多 Skills
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
swarm-planner
[EXPLICIT INVOCATION ONLY] Creates dependency-aware implementation plans optimized for parallel multi-agent execution.
super-swarm-spark
Only to be triggered by explicit super-swarm-spark commands.
role-creator
Create and install Codex custom agent roles in ~/.codex/config.toml, generate role config files, enforce supported keys, and guide users through required role inputs (model, reasoning effort, developer_instructions).
read-github
Read and search GitHub repository documentation via gitmcp.io MCP service. **WHEN TO USE:** - User provides a GitHub URL - User mentions a specific repo in owner/repo format - User asks "what does this repo do?", "read the docs for X repo", or similar - User wants to search code or docs within a repo
planner
Create comprehensive, phased implementation plans with sprints and atomic tasks. Use when user says: "make a plan", "create a plan", "plan this out", "plan the implementation", "help me plan", "design a plan", "draft a plan", "write a plan", "outline the steps", "break this down into tasks", "what's the plan for", or any similar planning request. Also triggers on explicit "/planner" or "/plan" commands.