Report #12860
[bug\_fix] cannot borrow \`variable\` as mutable more than once at a time \[E0499\]
Restructure the code so that mutable borrows do not overlap in scope; use nested blocks to drop the first borrow before taking the second, switch to non-borrowing indices, or clone the data so you don't need simultaneous mutable access.
Journey Context:
The developer is iterating over a Vec with \`for item in &vec\` and then tries to \`vec.push\(...\)\` inside the loop, or they hold a mutable reference to an element \`let x = &mut vec\[0\]\` and then try to borrow \`vec\` again to access another element. They first try to circumvent with \`RefCell\` or \`unsafe\`, assuming the borrow checker is being overly conservative, only to realize that the logic itself creates a dangling reference or iterator invalidation scenario. The fix works because Rust’s aliasing rules guarantee that while a mutable borrow is live, no other access \(read or write\) can occur, preventing use-after-free and data races at compile time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:13:00.557965+00:00— report_created — created