
Understand it
Passing &mut *value creates a shorter reborrow instead of moving the original mutable reference. This lets a helper work briefly and returns control to the outer borrower afterward.
A mutable reference can temporarily lend its access to another function. In twice, each bump(&mut *value) creates a shorter reborrow from the outer &mut i32. The first helper finishes before the second begins. The original reference is not consumed, so it can be used again after the helper calls. The important property is the timeline: there is one active writer at a time.
The * dereferences the outer reference to the value, and &mut forms a new mutable borrow of it. Rust often performs this reborrow implicitly at a call site, but writing it out makes the mechanism visible. If the first helper kept the reference beyond its call, the second exclusive borrow could not start. A return value tied to that borrow may also keep it active. Read compiler errors as a sequence of active loans rather than as a demand to clone a mutable reference; mutable references are not freely duplicable.
Try adding a print through value between the two bump calls, then after both calls. Both are fine if each reborrow has ended. Next, return the first reborrow from a helper and try to call bump again before its last use; the conflict shows why the short duration matters. Reborrowing is common in methods that coordinate several mutating helpers, and understanding it keeps such code simple without resorting to shared runtime mutation.
Read the code
fn bump(value: &mut i32) {
*value += 1;
}
fn twice(value: &mut i32) {
bump(&mut *value);
bump(&mut *value);
}The example makes the contract visible in code.
Try it
Trace each bump(&mut *value) in twice and mark where each reborrow ends.
What success looks like: You can say why value is usable for the second call, and why only one writer is ever active.
Check your understanding
Why is value usable for the second call?
Reveal the answer
- It was copied
- Each reborrow ends
- bump returns it
Correct: Each reborrow ends.
Go deeper
Common misconception: “value survives the first call because &mut references are Copy.”
&mut i32 is not Copy. &mut *value makes a shorter reborrow that ends when bump returns, so value is usable again for the second call.
- Follow the loans:
twiceholdsvalue: &mut i32. Eachbump(&mut *value)lends that access tobumpfor one call, and the loan ends on return. - Predict before checking: Start from
let mut n = 0; twice(&mut n);and predictn. Then predict whetherprintln!("{value}");compiles between the two calls. - Compare with evidence:
nis2, and the print compiles because neither reborrow is still active. Only one writer is live at any moment.
Transfer challenge: Write fn keep(value: &mut i32) -> &mut i32 { value } and hold its result across the next bump(&mut *value). Use the kept reference last and read the E0499 that the longer reborrow causes.
Connections
- Mutable Borrows: One temporary writer with exclusive access
- Partial Moves: Move one field while borrowing another
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Reborrowing (courseId "ownership", lessonId "reborrowing") Link: https://crabrix.com/learn/ownership/reborrowing/ Goal: Passing &mut *value creates a shorter reborrow instead of moving the original mutable reference. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=ownership/reborrowing) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.