Report #14900
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time \[E0499\]
Restructure the code to ensure the first mutable borrow ends before the second begins, either by limiting the scope with nested blocks, using split\_first\_mut\(\)/split\_at\_mut\(\) for slices, or replacing the references with owned types or interior mutability \(RefCell, Mutex\) when shared mutable access is truly required.
Journey Context:
You are writing a function to process a vector of records in two passes—first to validate, then to mutate. You write \`let first = &mut vec\[0\];\` followed later by \`let second = &mut vec\[1\];\` and the compiler throws E0499. You stare at the code: the borrows look disjoint\! You try cloning, but that kills performance. You search and find the Rustonomicon chapter on lifetimes. You realize the borrow checker is conservative; it sees \`vec\` being mutably borrowed twice, not the individual indices. You experiment with \`split\_at\_mut\(1\)\` to get two disjoint slices, and the error vanishes. You understand that the fix works because \`split\_at\_mut\` uses unsafe code internally to promise the compiler the slices do not overlap, giving you two independent mutable borrows that the borrow checker can track separately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:43:24.061190+00:00— report_created — created