rust-ownership
Skill0 starsChanged 3 months agoMITView on GitHub
Stops coding agents from "fixing" Rust borrow-checker errors with .clone(), Arc, RefCell or Box::leak when the real fix is to restructure ownership. Use when writing or repairing Rust code, when rustc reports E0382, E0499, E0502, E0506, E0515 or E0597, when a borrow checker error must be resolved, or when reviewing Rust code for unnecessary clones and allocations.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- gurinderu/crafttheir own version, first seen Nov 29, 2026
- lengrufeng2008/dsh-skill-librarytheir own version, first seen Nov 15, 2026
- adxptived/Rust-Skillstheir own version, first seen Oct 17, 2026
- dawidpereira/rust-skillstheir own version, first seen Mar 22, 2026
- huiali/rust-skillstheir own version, first seen Feb 9, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- huiali/rust-skills★ 47same name
- adxptived/Rust-Skills★ 1same name
- gurinderu/craft★ 1same name
- dawidpereira/rust-skills★ 0same name
- lengrufeng2008/dsh-skill-library★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 4 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
When rustc rejects your code with a borrow or move error, it usually gives you
- Distinctive: line 27
When you hit a borrow error, work in this order:
- Very specific: line 31
Change the signature: If a callee only reads, take &T / &str instead of T.
- Distinctive: line 32
Sequence the accesses: Do the read, finish with it, then do the write.
- Distinctive: line 34
Only then: consider owning the data — and when you do, say in one sentence why sharing or copying is the right design, not just what made …
- Very specific: line 68
Every claim above comes from compiling the programs in corpus/ with a real rustc and reading --error-format=json.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust ownership — do not clone your way out
When rustc rejects your code with a borrow or move error, it usually gives you
nothing to act on: on 5 of the 6 cases in this repo's corpus it emits no help
and no note at all. In the one case where it does offer a help, that help is
"consider cloning the value".
So the path of least resistance is to clone until it compiles. Do not take it. Cloning to escape a borrow conflict does not fix the conflict — it makes two objects where the code assumed one.
The rule
Never introduce .clone(), Arc, Rc, RefCell or Box::leak for the purpose
of silencing a compiler error. Those are designs, not fixes. Reach for them only
when the design genuinely calls for shared or owned data, and say so explicitly.
When you hit a borrow error, work in this order:
- Shorten the borrow. Bind only what you need (a
bool, ausize, an owned key) inside a tight scope so the borrow ends before the conflicting use. - Change the signature. If a callee only reads, take
&T/&strinstead ofT. - Sequence the accesses. Do the read, finish with it, then do the write.
- Use the API built for it.
entry,split_at_mut, indices,std::mem::take. - Only then consider owning the data — and when you do, say in one sentence why sharing or copying is the right design, not just what made the error go away.
Per-error playbook
| Code | What it means | Do NOT | Do |
| E0382 | Value used after being moved | Pass x.clone() | Take &T in the callee |
| E0499 | Two mutable borrows at once | Clone the collection | Sequence them, or split_at_mut |
| E0502 | Mutable borrow while immutably borrowed | Clone the looked-up value | End the read in a tight scope, or use entry |
| E0506 | Assign to a borrowed value | Clone the struct | Shorten the reference's lifetime |
| E0515 | Return a reference to a local | Box::leak | Return the owned value |
| E0597 | Borrow outlives its referent | Wrap in Rc<RefCell<_>> | Restructure so the value outlives the borrow |
The one that actually bites
E0499 and E0502 are the dangerous ones. Cloning there compiles cleanly, passes tests, and is silently wrong: the two halves of the code now mutate different objects, so writes through one are invisible to the other.
clippy::redundant_clone will not save you. It only fires when the original is
never used again. In exactly these cases the original is still used — that is
why the borrow conflicted — so clippy stays silent.
When cloning IS right
Cloning is not banned. It is correct when the data genuinely needs independent ownership: sending a value to another thread, storing a snapshot that must not change, or when profiling shows the copy is cheap and the restructure is not worth it. The test is whether you can state the reason without referring to the compiler error.
Evidence
Every claim above comes from compiling the programs in corpus/ with a real rustc
and reading --error-format=json. See EVIDENCE.md, which is
generated by node scripts/extract.mjs and re-verified in CI.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

