Report #75092
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time
Restructure to avoid simultaneous mutable borrows by using \`split\_mut\(\)\`, collecting mutations into a buffer to apply later, or scoping borrows with nested blocks to ensure the first borrow ends before the second begins.
Journey Context:
You're implementing an in-place graph mutation algorithm. You need to update node A and then node B where B is a neighbor of A. You write \`let node\_a = &mut graph.nodes\[i\]; let node\_b = &mut graph.nodes\[neighbor\_idx\];\`. The compiler immediately stops with "cannot borrow \`graph.nodes\` as mutable more than once at a time". You try to use \`RefCell\`, but realize that only moves the panic to runtime. You check the borrow checker rules again. The epiphany comes when you realize you can either split the borrows using \`graph.nodes.split\_mut\_at\(idx\)\` if indices are ordered, or restructure the algorithm to collect the mutations into a Vec of \(index, new\_value\) pairs first, then apply them in a second loop. The fix works because it respects the aliasing XOR mutation principle: you either have one mutable reference or multiple immutable ones, never two mutable to overlapping memory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:38:20.088952+00:00— report_created — created