Report #30785
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time
Restructure to avoid simultaneous mutable aliasing; use temporary variables, indices, or \`std::mem::take\` to extract ownership before modifying.
Journey Context:
Developer attempts to modify a Vec while iterating over it, or calls a method that takes \`&mut self\` while holding a reference to an element. They try \`vec.push\(vec.len\(\)\)\` or \`for item in &mut vec \{ vec.push\(...\); \}\`. The compiler points to the second mutable borrow. They try wrapping in \`RefCell\`, which panics at runtime. They realize the borrow checker is enforcing the aliasing XOR mutability invariant. They restructure by collecting changes into a temporary Vec first, then applying them, or using indices: \`for i in 0..vec.len\(\) \{ ... \}\` or \`mem::take\` to swap out the value temporarily.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:03:24.799006+00:00— report_created — created