po4yka/rust-skills / skills/rust-panic-safety
rust-panic-safety
VerifiedUse when guarding an extern "C", extern "system", or JNI entry point with catch_unwind, choosing panic = "unwind" or "abort", installing a panic hook, disposing of a panic payload, fixing an UnwindSafe bound with AssertUnwindSafe, or triaging an abort such as "panic in a function that cannot unwind". Also use when a panic can escape a foreign callback, spawned task, thread, or Drop, or when replacing unwrap or expect on an FFI-reachable path. Owns the panic policy at a C ABI boundary.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 11.5 KB |
| references/boundary-patterns.md | markdown | 16.4 KB |
| references/drop-guard.md | markdown | 2.0 KB |
| references/jni-boundary.md | markdown | 8.4 KB |
| references/panic-hook.md | markdown | 3.4 KB |
| references/panic-strategy.md | markdown | 2.2 KB |
| references/unwind-state.md | markdown | 2.3 KB |
| references/unwrap-audit.md | markdown | 10.0 KB |
references/panic-strategy.md
View on GitHub# Panic Strategy
Extended reference for the `rust-panic-safety` skill. Read this when you set or review the
`panic` key of a profile, or when a guard must keep working in the shipped build.
## Unwind or abort
- `panic = "unwind"` (default) keeps panics catchable; landing pads add code. Use it when a
panic must be survived: a shared library inside a host process, a server that isolates a
request, any FFI boundary that returns an error to the caller.
- `panic = "abort"` aborts at the panic site. It is smaller and marginally faster. Use it when
no guard depends on catching, for example a standalone binary where a panic is a crash
anyway. It silently turns every `catch_unwind` guard into dead code.
```toml
[profile.release]
panic = "unwind" # required if any entry point relies on catch_unwind
overflow-checks = true # a wrapped length becomes a panic, not a bad slice bound
debug = "line-tables-only" # file and line when you symbolicate a backtrace offline
```
Rules:
- Cargo reads manifest profiles only from the workspace root. A `[profile]` table in a member
manifest has no effect, and a per-package override cannot set `panic`. A config-file
profile, `CARGO_PROFILE_<NAME>_PANIC`, and `-C panic` in any rustflags source override the
manifest.
- Cargo ignores the `panic` key for tests, benchmarks, build scripts, and proc macros. A
`#[should_panic]` test therefore runs under unwind even when release aborts. Do not read a
green test run as proof that the shipped library unwinds.
- State the reason for the strategy in a comment next to the `panic` key.
## Check the shipped strategy
Run the `--print cfg` check with the same `--target`, `--profile`, and environment as the
shipping build. It then reflects every source of the strategy: the root manifest profile,
`[profile.<name>]` in `.cargo/config.toml`, `CARGO_PROFILE_<NAME>_PANIC`, `RUSTFLAGS`,
`CARGO_ENCODED_RUSTFLAGS`, `build.rustflags`, and `target.<triple>.rustflags`. Without
`--target`, Cargo builds for the host and skips the rustflags of the shipping triple, so the
check can print `unwind` for a library that ships with `abort`. Replace `--release` with
`--profile <name>` when the shipping profile is not `release`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |