Report #30938
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time \[E0499\]
Wrap the first mutable borrow in a nested scope block \`\{\}\` so the borrow expires before the second one, or call \`std::mem::drop\(\)\` on the first borrow handle to explicitly end its lifetime.
Journey Context:
Developer writes a loop that calls \`iter\_mut\(\)\` on a Vec, then inside the loop tries to push to the same Vec. The compiler flags the mutable borrow from the iterator and the borrow from \`push\`. The developer tries adding random lifetime annotations \`'a\` thinking it will extend the borrow, then realizes that mutable exclusivity is the law. They try \`RefCell\` unnecessarily before learning that borrows end at the last use \(NLL\), so wrapping the iterator usage in a block or calling \`drop\(iter\)\` before the push allows the code to compile without runtime overhead.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:19:11.518024+00:00— report_created — created