Report #58318
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time / cannot borrow \`x\` as mutable because it is also borrowed as immutable
Scope the immutable borrow to end before the mutable borrow begins by introducing a nested block or cloning the data needed from the immutable borrow so the borrow is released before mutation.
Journey Context:
Developer iterates over a Vec with \`for s in &vec\`, then tries to \`vec.push\(\)\` inside the loop. The compiler errors because the iterator holds an immutable borrow of \`vec\` while \`push\(\)\` requires a mutable borrow. Developer tries collecting references first, attempts \`drop\(s\)\` manually, then realizes they must either scope the iteration in a block to drop the borrow, clone the items into a new collection first, or iterate by index in reverse to avoid the simultaneous borrow.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:22:44.606120+00:00— report_created — created