Report #78787
[bug\_fix] E0499 - cannot borrow \`x\` as mutable more than once at a time
Restructure the code so the first mutable borrow ends before the second begins \(introduce a nested block \`\{ let temp = &mut x; ... \}\`\), or use \`split\_first\_mut\(\)\` / \`split\_at\_mut\(\)\` for slices. Root cause: Rust’s borrow checker enforces that mutable references \(&mut T\) must be unique and cannot overlap to prevent data races.
Journey Context:
Developer is writing a function that scans a Vec to find an element matching a predicate and then modifies another element in the same vector based on that search. They write: \`let idx = vec.iter\_mut\(\).position\(\|x\| x > 5\).unwrap\(\); let item = &mut vec\[idx\];\`. The compiler throws E0499 because \`iter\_mut\(\)\` holds a mutable borrow of the entire Vec, while \`&mut vec\[idx\]\` tries to borrow mutably again. The developer tries to clone the data, but that’s inefficient. They search and find that introducing a scope block \`\{ let idx = ... \}\` drops the first borrow before the second, or using \`vec.split\_first\_mut\(\)\` pattern works. They realize the borrow checker is preventing overlapping mutable access which would be unsafe.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:50:08.845162+00:00— report_created — created