Report #86408
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time \(E0499\)
Restructure the code to drop the first mutable borrow before creating the second, or use \`Vec::retain\`/\`Vec::drain\` for in-place modification. Common patterns include collecting indices to modify first, using \`split\_first\_mut\` for pairwise iteration, or temporarily extracting values with \`std::mem::take\`. If the borrows are truly overlapping and required for the algorithm, interior mutability \(\`RefCell\`\) or re-architecting to single-owner patterns is necessary.
Journey Context:
Developer writes a loop to iterate over a vector with \`for item in &mut vec\` while simultaneously trying to push to the same vector inside the loop \(\`vec.push\(...\)\`\), or attempts to get two mutable references with \`let a = &mut vec; let b = &mut vec;\`. The compiler emits E0499 pointing to the second borrow attempt. Developer initially tries to wrap the collection in \`RefCell\` immediately, but realizes this pushes the panic to runtime and doesn't solve the fundamental aliasing issue if the borrows overlap. They then realize they should collect the new items into a separate \`Vec\` and \`extend\` after the loop, or use \`retain\` if filtering, recognizing that Rust is preventing iterator invalidation bugs common in C\+\+.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:37:31.703268+00:00— report_created — created