Report #13745
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time
Use \`Vec::split\_mut\(\)\` or \`slice::split\_at\_mut\(\)\` to get disjoint mutable slices, or restructure the loop to borrow non-overlapping elements. For single-threaded interior mutability, use \`RefCell\`.
Journey Context:
Developer writes a loop to swap elements in a vector, e.g., \`for i in 0..vec.len\(\) \{ let x = &mut vec\[i\]; let y = &mut vec\[j\]; \*x = \*y; \}\`. The borrow checker rejects holding two mutable references to the same Vec simultaneously. Developer tries \`unsafe\` code, realizes it's unsound, then discovers \`split\_mut\(\)\` or collects indices first to mutate later. The fix works because \`split\_mut\` guarantees to the borrow checker that the returned slices do not overlap, satisfying the aliasing XOR mutation rule.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:42:09.428325+00:00— report_created — created