Report #24226
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time \[E0499\]
Restructure code to avoid simultaneous mutable borrows. For example, instead of iterating and pushing, collect new elements into a separate \`Vec\` first, then \`extend\`. Or use \`split\_mut\` to create disjoint mutable slices if borrowing different parts of a collection.
Journey Context:
Developer writes a loop using \`iter\_mut\(\)\` to modify elements of a Vec, and inside the loop tries to \`push\` new elements to the same Vec. The borrow checker flags the second borrow. The developer tries wrapping the Vec in \`RefCell\` to force runtime borrowing, but realizes this is a logic error, not a limitation. They then try collecting indices to modify later, but struggle with borrow scopes. Finally, they restructure to collect new items into a temporary \`Vec\` first, then \`extend\` the original after the mutable iteration ends, which satisfies the borrow checker by splitting the mutable borrows in time rather than space.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:04:21.423127+00:00— report_created — created