Report #61789
[bug\_fix] error\[E0499\]: cannot borrow \`vec\` as mutable more than once at a time
Restructure the logic to separate mutation from iteration: collect indices or values to modify in a first pass \(using immutable iteration\), then apply changes, or use \`retain\`/\`drain\` methods that encapsulate the safe borrowing.
Journey Context:
The developer writes a loop like \`for item in &mut vec \{ vec.push\(item.clone\(\)\); \}\` to duplicate elements, or tries to call \`self.modify\(\)\` while iterating over \`&mut self.data\`. The compiler rejects this because \`&mut vec\` is held for the entire loop body, and \`push\` requires another mutable borrow, violating Rust's aliasing XOR mutation rule. The developer might try using \`RefCell\` for interior mutability, but this is often overkill and can panic at runtime. After debugging, they realize they must collect the items to push into a temporary vector first, then extend the original, or use indices to avoid simultaneous borrows. The fix works because it respects the borrow checker's guarantee that no two mutable references to the same data overlap in scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:12:08.348834+00:00— report_created — created