Skip to content

po4yka/rust-skills / skills/rust-panic-safety

rust-panic-safety

Verified

Use 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.

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`.
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall