Report #8479
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time \[E0499\] when holding an iterator while pushing
Restructure the code to release the first borrow before the second mutation, or use indices instead of iterators. For head/tail patterns, use \`split\_first\_mut\(\)\`. Root cause: Rust enforces Aliasing XOR Mutation—while an iterator \(a borrow\) is live, the source collection cannot be mutably borrowed.
Journey Context:
Developer writes a loop to drain a \`Vec\` and conditionally push new derived strings back into the same vec. They hold an iterator with \`let mut iter = vec.iter\(\)\` and inside the loop try \`vec.push\(suffix.clone\(\)\)\`. The compiler hits E0499. Developer tries to scope the iterator borrow with \`\{\}\` blocks but the logic requires interleaving. They attempt \`RefCell>\` but hit runtime panics. After reading the Error Index and the Nomicon, they realize the iterator holds a borrow to the vec's internal buffer. The architectural fix is to collect new items into a temporary \`Vec\` during iteration, then \`vec.extend\(temp\)\` after the loop, avoiding simultaneous borrows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:39:49.914995+00:00— report_created — created