Back to library

🦀Rust Borrow Checker Deep Dive

Build a precise mental model of Rust's borrow checker — from the shared-XOR-mutable invariant through NLL and reborrows — so you can refactor tangled code into a clean version the compiler accepts without reaching for clone().

Applied14 drops~2-week path · 5–8 min/daytechnology

Phase 1The Invariant the Checker Proves

Shared XOR mutable and the invariant the checker proves

4 drops
  1. The borrow checker has exactly one job

    7 min

    The borrow checker has exactly one job

  2. Aliasing is safe. Mutation is safe. Aliasing PLUS mutation is the bug.

    6 min

    Aliasing is safe. Mutation is safe. Aliasing PLUS mutation is the bug.

  3. A borrow has a birth, a span, and a death — and the checker tracks all three

    7 min

    A borrow has a birth, a span, and a death — and the checker tracks all three

  4. Move, copy, borrow, lifetime — the four primitives, no more

    6 min

    Move, copy, borrow, lifetime — the four primitives, no more

Phase 2Twenty Borrow Errors, Categorized

Debug 20 classic borrow errors and name each failure mode

5 drops
  1. Move conflicts — when the source is no longer the owner

    7 min

    Move conflicts — when the source is no longer the owner

  2. E0502: 'cannot borrow as mutable because it is also borrowed as immutable'

    7 min

    E0502: 'cannot borrow as mutable because it is also borrowed as immutable'

  3. E0499: two mutable borrows — when 'just for a moment' isn't allowed

    7 min

    E0499: two mutable borrows — when 'just for a moment' isn't allowed

  4. E0507: 'cannot move out of borrowed content'

    6 min

    E0507: 'cannot move out of borrowed content'

  5. Decode any borrow error in under a minute

    6 min

    Decode any borrow error in under a minute

Phase 3What NLL, Reborrows, and Splits Unlock

NLL, reborrows, and split borrows expand what's allowed

4 drops
  1. NLL: borrows die at last use, not at the closing brace

    6 min

    NLL: borrows die at last use, not at the closing brace

  2. Reborrows: how *mut* methods take callbacks without losing the lock

    7 min

    Reborrows: how *mut* methods take callbacks without losing the lock

  3. Disjoint field borrows: how the checker proves two fields don't overlap

    7 min

    Disjoint field borrows: how the checker proves two fields don't overlap

  4. Cell, RefCell, Mutex: the runtime escape hatch

    7 min

    Cell, RefCell, Mutex: the runtime escape hatch

Phase 4Refactor Without Clones

Refactor a tangled function past the checker without clones

1 drop
  1. Refactor a tangled function past the borrow checker — no clones

    10 min

    Refactor a tangled function past the borrow checker — no clones

Frequently asked questions

What is the borrow checker actually trying to prove about my code?
This is covered in the “Rust Borrow Checker Deep Dive” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why does shared XOR mutable matter — what bugs does it prevent?
This is covered in the “Rust Borrow Checker Deep Dive” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What changed when Non-Lexical Lifetimes (NLL) landed?
This is covered in the “Rust Borrow Checker Deep Dive” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
When is reaching for .clone() okay, and when is it hiding a design problem?
This is covered in the “Rust Borrow Checker Deep Dive” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
How do reborrows and split borrows let me do things the checker first rejected?
This is covered in the “Rust Borrow Checker Deep Dive” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.