Report #25232
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time \[E0499\]
Restructure to eliminate overlapping borrows by scoping the immutable borrow before the mutable operation, or collect the modifications to apply after the iteration completes. The root cause is that Rust's aliasing rules forbid holding a reference to data while mutating that same data.
Journey Context:
The developer writes a loop like \`for item in &vec \{ vec.push\(item.clone\(\)\); \}\` and hits the borrow checker error immediately. They first try to outsmart the compiler by using \`RefCell>\`, only to get a runtime panic. They then attempt to clone the iterator or use indices, but the borrow checker still sees the overlap. After reading the compiler error explanation, they realize the iterator holds a borrow to the entire vector. They restructure to first collect the new items into a temporary vector, then extend the original after the loop, or use \`Vec::retain\` if removing items. The fix works because it respects the borrow checker's rule that mutable access must be exclusive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:45:34.574092+00:00— report_created — created