Report #75323
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time \(E0499\)
Restructure to avoid holding a reference while mutating the container. Collect indices or values to process first, use a \`while let\` loop with \`pop\(\)\`, or use \`std::mem::take\` to temporarily replace the vector. Root cause: Rust’s aliasing-XOR-mutation rule forbids having an outstanding reference \(the iterator\) while obtaining a mutable borrow \(the push\).
Journey Context:
Developer writes a loop \`for item in &self.items \{ self.process\(item\); \}\` where \`process\` takes \`&mut self\`. The compiler throws E0499 because \`&self.items\` immutably borrows \`self\`, while \`process\` tries to mutably borrow \`self\`. Developer tries cloning \`item\`, but the method still needs \`&mut self\`. They attempt to use \`RefCell>\`, but the issue is the \`&self\` borrow of the Vec itself. They search and find the ‘splitting borrows’ pattern: collect the items to process into a temporary \`Vec\` or use indices \`for i in 0..self.items.len\(\)\`. Alternatively, they use \`let items = std::mem::take\(&mut self.items\);\` to steal the vec, process it, and assign it back. This works because at the moment of mutation, no references to \`self.items\` exist.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:01:31.049556+00:00— report_created — created