| name | rust-borrow-checker |
| description | Debug Rust ownership, borrowing, and lifetime errors. Use when encountering borrow checker errors (E0382, E0502, E0597, etc.) or when code won't compile due to ownership issues. |
- Each value has exactly one owner - When the owner goes out of scope, the value is dropped
- You can have either one mutable reference OR any number of immutable references - Never both simultaneously
- References must always be valid - No dangling references, lifetimes must be sufficient
Understanding these rules is the key to fixing borrow checker errors.
- Diagnose a borrow checker error (paste the error)
- Fix a lifetime annotation issue
- Fix an ownership transfer problem
- Fix a mutable/immutable borrow conflict
- Understand a specific error code
Paste the compiler error or describe the issue, then I'll route to the appropriate workflow.
E0382 (use of moved value): Clone, use references, or restructure to avoid the move E0502 (cannot borrow as mutable, already borrowed as immutable): Separate the borrows into different scopes, or use interior mutability (RefCell, Mutex) E0499 (cannot borrow as mutable more than once): Split into separate scopes or use indices instead of references E0597 (borrowed value does not live long enough): Extend the lifetime of the owner, or use owned types instead E0506 (cannot assign, already borrowed): Complete borrow before assignment, or use Cell/RefCell
Core Rules:
- ownership-rules.md - The three ownership rules with examples
- borrowing-rules.md - Borrowing and reference rules
- lifetime-syntax.md - Lifetime annotation patterns and elision
Problem Solving:
- common-errors.md - Detailed breakdown of E0XXX errors
- patterns.md - Clone, Rc, Arc, RefCell, Cow patterns