Agent skill
rust-code-debugger
Diagnoses and fixes Rust compile errors, borrow-checker issues, runtime panics, and logic bugs with clear explanations and idiomatic solutions.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/rust-code-debugger
SKILL.md
Rust Code Debugger
Instructions
-
Understand the user request:
Identify whether the problem is a compiler error, borrow-checker conflict, runtime panic, undefined behavior risk, or incorrect logic. Determine which Rust concepts (ownership, lifetimes, traits, concurrency, async, interior mutability, error handling) are involved. -
Reproduce the mental execution flow:
Walk through the code step by step, tracking:- variable bindings and moves
- reference creation and lifetimes
- mutation paths (mutable aliasing, interior mutability)
- control-flow branches
- async
.awaitsuspension points - thread boundaries and
Send/Syncrequirements
-
Identify the root cause with precision:
Provide a detailed explanation grounded in Rust’s guarantees:- why the borrow checker rejected a pattern
- why a value was moved earlier than expected
- why a panic occurred (
unwrap, index out of bounds, threading, channel behavior, etc.) - why lifetimes cannot be inferred
- why trait resolution fails
- why async runtime ordering causes issues
-
Provide an idiomatic and minimal fix:
Offer a correction that adheres to Rust best practices, such as:- replacing
&mutconflicts with scoped blocks or.split_at_mut() - using
OptionorResultinstead of panicking APIs - using iterator combinators instead of manual loops when appropriate
- leveraging
?for clean error propagation - using
Arc<Mutex<T>>orArc<RwLock<T>>for shared mutable state across threads - applying
Cow<'a, T>for flexible ownership - introducing helper structs or newtypes to reflect invariant boundaries
Keep the fix minimal but idiomatic, avoiding unnecessary complexity.
- replacing
-
Suggest robust alternatives when relevant:
If the user’s current approach is fragile or overly complex, gently recommend stronger patterns:- Use RAII guards for cleanup
- Introduce separate data structures to enforce invariants
- Replace manual state machines with enums
- Use async channels or tasks instead of locks
- Avoid premature cloning; prefer borrowing when possible
- Structure code into smaller functions to reduce lifetime complexity
-
Recommend preventive strategies:
Provide practical guidance for long-term improvement, including:- writing smaller functions to help lifetime inference
- adding
#[derive(Debug)]for easier inspection - avoiding unnecessary
clone()calls - adopting clippy (
cargo clippy) and rustfmt - using feature flags,
miri, andcargo-udepsto maintain healthy code - structuring modules around ownership boundaries
-
Maintain clarity and educational value:
Every explanation should not only fix the bug but help the user understand how Rust’s model leads to safer and more predictable code.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?