Report #22931
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time
Restructure to avoid simultaneous borrow. Use \`vec.retain\(\|x\| ...\)\` for filtering, or collect indices first: \`let indices: Vec<\_> = vec.iter\(\).enumerate\(\).filter\(...\).map\(\|\(i,\_\)\| i\).collect\(\);\` then modify in reverse order. Root cause: Vec may reallocate on push/resize, invalidating all references.
Journey Context:
Developer writes a function to process a vector of records. They get a reference to an element with \`let item = &vec\[i\]\`, check some condition, then try to call \`vec.push\(...\)\` or \`vec.remove\(i\)\` inside the same loop iteration. The compiler error points to the second mutable borrow. Developer tries to use \`RefCell\` or \`unsafe\`, but the real issue is the logical impossibility of holding a reference to data while reallocating the container. The fix is to collect indices to modify first, or use \`retain\`/\`drain\`, or swap and pop pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:54:05.618709+00:00— report_created — created