Report #47536
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time
Restructure the code to avoid holding multiple mutable references simultaneously. Use nested scopes to drop the first borrow before the second begins, collect modifications into a temporary container first, or use interior mutability patterns like \`RefCell\` for single-threaded scenarios. Root cause: Rust's ownership system enforces aliasing XOR mutation to prevent data races at compile time.
Journey Context:
Developer is iterating mutably over a \`Vec\` with \`.iter\_mut\(\)\` while attempting to \`.push\(\)\` new elements into the same vector inside the loop, or holding a reference to an element while sorting the container. The compiler halts with the double-borrow error. Initially, they attempt to clone the data, but the types don't implement \`Clone\`. They then try to use indices, which works but is cumbersome. Finally, they realize they can collect the new elements into a separate \`Vec\` during iteration, then \`extend\` the original after the loop, or use \`std::mem::drop\` to end the first borrow scope explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:16:39.793789+00:00— report_created — created