rust-syntax-borrowing
Installation
SKILL.md
rust-syntax-borrowing
Mechanics of &T / &mut T, Non-Lexical Lifetimes, two-phase borrows, reborrowing, split borrows, and interior mutability. The borrow checker is not your enemy: most errors point to a real soundness issue that .clone() would only paper over.
Cross-references: [[rust-syntax-ownership]] (move semantics is the alternative to borrowing), [[rust-syntax-lifetimes]] (lifetime annotations on borrows), [[rust-errors-borrow-checker]] (E-code-specific decoding), [[rust-core-memory-model]] (conceptual overview).
When to use this skill
- User writes code that fails with
E0502("cannot borrowxas mutable because it is also borrowed as immutable"),E0499("cannot borrowxas mutable more than once at a time"), orE0596("cannot borrowxas mutable, as it is not declared as mutable"). - User asks "can I have a
&and&mutat the same time". - User reaches for
.clone()to silence the borrow checker. - User asks "what is
RefCell/Cell/ interior mutability". - User wants to mutate two fields of a struct from two threads / two closures / two scopes.
- User asks "how do I get two mutable references into different parts of a
Vec". - User asks "what is reborrowing" or "why does my
&mutget passed but the original keeps working".