Report #45991
[bug\_fix] cannot borrow \`items\` as mutable more than once at a time \[E0499\]
Restructure to calculate indices or lengths before mutating, use \`Vec::retain\`, or scope the mutable borrow to end before the push. Root cause: A mutable borrow of the Vec is held for the entire iteration scope, and since \`push\` might reallocate, it cannot coexist with any outstanding reference.
Journey Context:
Developer is building an AST walker. Inside a method, they iterate with \`for child in &self.children\` to find a target node by reference equality, then attempt \`self.children.push\(new\_sibling\)\` inside the same loop. The borrow checker throws E0499. Developer tries cloning the child for comparison, breaking identity semantics. They try \`iter\_mut\(\)\` but that doesn't allow finding by reference. They descend into a rabbit hole of \`split\_first\_mut\` and raw pointers. Eventually, they realize they can find the index first using \`position\(\)\`, drop the borrow, then push, or collect changes into a separate Vec and apply them after the loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:40:14.893106+00:00— report_created — created