Design and review Rust ownership, borrowing, lifetimes, and interior mutability so data flow matches the domain model.
SkillScore95Maintained
Automatic
◆Coding pack
Last verified 8/16/2026
What it changes
Passed 21 of 22 test cases with the skill, and 20 of 22 without it.
Without skill91%
With skill95%
Checks it passed that the model alone missed
The response avoids proposing a manual index loop over collection length to bypass borrow checking.
The response refactors the code using standard slice or collection API methods rather than raw index lookup loops.
1 fixed20 passed either way1 still failing0 broke
Pass-rate lift
+5 pp
Tokens
+17%
Agent turns
0%
Response time
-16%
Model gemini-3.6-flashMeasured 8/16/2026v121 of 22 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
A test case the skill fixed. Same model, same prompt, with and without the skill.
Prompt
I am getting compiler error E0502 in my Rust project because I'm trying to modify elements inside a collection while simultaneously holding an active read reference to it. Here is the offending function snippet. Please refactor the code to resolve the borrow checker conflict, and provide a clear explanation of how ownership and reference lifetimes were adjusted.
What was checked, without and with the skill
Checked
Without skill
With skill
The response refactors the code using standard slice or collection API methods rather than raw index lookup loops.
Missed
Passed
The response avoids proposing a manual index loop over collection length to bypass borrow checking.
Missed
Passed
case-01 · gemini-3.6-flash · 8/16/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md62 lines2 files
Rust Ownership Borrowing
Use this skill to make ownership shape match the program's data flow. Treat
borrow-checker errors as design feedback: decide who owns each value, how long
access must last, and whether mutation needs exclusivity or a different data
shape.
Core Workflow
Identify the owner of each value crossing the failing code path.
Decide the required access for each function: own, shared borrow, mutable
borrow, or shared ownership.
Shorten borrows before changing types. Introduce blocks, temporary values,
helper functions, or earlier extraction so references end before mutation.
Prefer moving values when the caller no longer needs them. Prefer borrowing
when the caller retains ownership. Clone only when duplicate ownership is
intentional and the cost is acceptable.
Replace self-referential or graph-like designs with IDs, indices, arenas, or
ownership trees before reaching for Rc<RefCell<_>>.
Use Rc for single-threaded shared ownership and Arc for cross-thread
shared ownership. Add Cell, RefCell, Mutex, or RwLock only when the
mutation model is explicit.
Add tests that exercise the ownership-sensitive behavior, not just the
compiler error that prompted the change.
Signature Rules
Take T when the function consumes or stores the value.
Take &T when the function only reads during the call.
Take &mut T when the function must mutate and no other access should occur.
Return owned values unless the returned reference is clearly tied to an input
lifetime.
Avoid accepting &Vec<T>, &String, or &PathBuf when &[T], &str, or
&Path expresses the needed capability.
Avoid adding lifetime parameters to structs unless the struct truly borrows
data owned elsewhere. Owned fields are usually simpler.
Common Fix Patterns
Read references/borrow-patterns.md when resolving non-trivial compiler