agentleFS
rainoftimerainoftime/pl-skills/rust-borrow-checker/SKILL.md

rust-borrow-checker

Skill17 starsChanged 10 months agoApache-2.0View on GitHub

Implements Rust-style ownership and borrowing verification. Use when:

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Start with owned values, add borrowing

    line 59
  2. Distinctive:

    Use lifetime elision rules for ergonomics

    line 61
  3. Distinctive:

    Consider async/await lifetime interactions

    line 62

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Borrow Checker

Implements Rust-style ownership, borrowing, and lifetime verification.

When to Use

  • Building memory-safe languages
  • Implementing borrow checking
  • Creating safe systems languages
  • Verifying data race freedom
  • Implementing affine/linear types

What This Skill Does

  1. Tracks ownership - Each value has single owner
  2. Enforces borrowing - Mutable/immutable references
  3. Verifies lifetimes - Reference validity
  4. Detects data races - At compile time

Key Concepts

ConceptDescription
OwnershipEach value has single owner
BorrowReference to owned value
LifetimeDuration reference is valid
RegionScope where reference valid
MoveTransfer ownership

Borrow Rules

RuleDescription
One mutableOnly one mutable borrow OR many immutable
No danglingReferences must not outlive referent
Move vs copyCopy for Copy types, move otherwise
Drop orderBorrows must be released before drop

Tips

  • Start with owned values, add borrowing
  • Implement NLL (non-lexical lifetimes) for better UX
  • Use lifetime elision rules for ergonomics
  • Consider async/await lifetime interactions
  • Handle unsafe blocks with care

Related Skills

  • ownership-type-system - Basic ownership types
  • linear-type-implementer - Linear types (generalization)
  • race-detection-tool - Dynamic race detection
  • separation-logician - Memory safety proofs

Canonical References

ReferenceWhy It Matters
Matsakis & Klock, "The Rust Language: Memory Model and Lifetime System" (2014)Original Rust ownership and borrowing design
Rust Reference, Chapter 4: "Lifetimes and Borrowing"Official lifetime and borrow specification
N. Matsakis, "A Primer on Rust Lifetimes" (blog series, 2014-2016)Deep dives on borrow checker design decisions
N. Matsakis & R. Klock, "The Rust Borrow Checker" (Rust Belt Rust 2016)Overview of borrow checker implementation

Tradeoffs and Limitations

Design Choices

ApproachProsCons
Lexical lifetimesSimpleLess precise
NLLBetter errorsComplex
PoloniusMost preciseSlow

Limitations

  • Learning curve for users
  • Some valid programs rejected (escape analysis)
  • Unsafe code circumvents guarantees
  • Complex interactions with async
  • Borrow checker is complex to implement

Research Tools & Artifacts

Rust borrow checker implementations:

ToolWhat to Learn
rustc borrow checkerProduction implementation
PoloniusNLL algorithm
OxideReference implementation

Key Papers

  • Matsakis & Klock - Rust design papers
  • NLL papers - Non-lexical lifetimes

Research Frontiers

1. Polonius

  • Goal: More precise borrow checking
  • Approach: Move errors as dataflow facts
  • Papers: "Polonius: A New Borrow Checker" (Jung et al., 2018)
  • Status: Experimental in rustc

2. Async/await and Lifetimes

  • Goal: Better lifetime handling in async code
  • Approach: Extended lifetime rules for generators
  • Papers: "Rust RFC 2394: async/await"

3. Formal Verification of Rust

  • Goal: Prove memory safety formally
  • Approach: RustBelt, semantic type system
  • Papers: Jung et al. "RustBelt: Securing Rust" (POPL 2018)

Implementation Pitfalls

PitfallReal ConsequenceSolution
NLL complexityWrong error messagesCareful dataflow algorithm
Lifetime inferenceOverly conservativeBetter region inference
Async interactionsRejected valid codeExtend lifetime rules
Unsafe escape hatchLost guaranteesClear unsafe boundaries

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.