Report #72440
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time
Narrow the scope of the first mutable borrow using explicit braces \`\{\}\` so it ends before the second borrow begins, or use \`split\_mut\(\)\` methods to create disjoint mutable views of collections.
Journey Context:
Developer writes a function that iterates mutably over a \`Vec\` while also trying to push new elements into it, or holds a reference to an element while modifying the vector. The compiler errors with "cannot borrow \`vec\` as mutable more than once". Developer attempts to use indices instead of references \(e.g., \`vec\[i\]\`\), but the borrow checker still sees it as a mutable borrow of the whole vec. They learn about the "aliasing XOR mutability" rule. They refactor by first collecting new elements into a temporary \`Vec\`, then using \`vec.extend\(temp\_vec\)\` after the first borrow scope ends. Alternatively, for disjoint slices, they use \`vec.split\_at\_mut\(idx\)\` to get two separate mutable slices that the borrow checker allows simultaneously.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:10:53.249019+00:00— report_created — created