Report #87091
[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. For collections, use \`split\_at\_mut\(\)\` or \`split\_first\_mut\(\)\`. For single-threaded interior mutability, wrap the data in \`RefCell\`. The root cause is Rust's aliasing XOR mutation guarantee: you cannot have two mutable references \(\`&mut T\`\) to the same data simultaneously because it violates memory safety \(data races/use-after-free\).
Journey Context:
You're iterating over a vector with \`iter\_mut\(\)\` while inside the loop you try to push a new element to the same vector. The compiler throws E0499. You try to use \`Vec::push\(\)\` while holding a mutable reference to an element. Confused, you search and learn that \`iter\_mut\(\)\` borrows the whole vector exclusively. You realize you need to collect indices first, or use \`split\_at\_mut\(\)\` to partition the vector, or clone the data. If it's a single-threaded graph traversal, you might wrap nodes in \`RefCell\` to allow interior mutability, understanding that \`RefCell\` moves borrow checking to runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:46:28.753033+00:00— report_created — created