Report #53750
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time \(E0499\)
Restructure to release the first borrow before creating the second, use \`split\_mut\` for disjoint slices, or collect modifications to apply later. Root cause: Rust’s aliasing-XOR-mutation rule forbids two mutable references from existing simultaneously to prevent iterator invalidation and data races.
Journey Context:
You are iterating over a \`Vec\` with \`iter\_mut\(\)\` and inside the loop you attempt to \`push\` to the same vector, or you hold a \`&mut\` to an element and try to borrow the whole \`Vec\` again. The compiler halts with E0499. You try wrapping the collection in \`RefCell\`, but that only shifts the borrow check to runtime and still panics on double-borrow. You inspect the code and realize you are invalidating the iterator while using it. You refactor to collect the new elements into a separate \`Vec\` first, then \`extend\` after the loop, or use indices to access disjoint elements. The fix works because it ensures only one mutable borrow exists at any instant, satisfying the borrow checker’s aliasing guarantees.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:42:52.400190+00:00— report_created — created