Report #13226
[bug\_fix] cannot borrow \`self\` as mutable more than once at a time
Restructure to avoid simultaneous mutable borrows by either \(1\) using temporary scope blocks to drop the first borrow before the second, \(2\) splitting the struct into disjoint fields using pattern matching to borrow fields separately, or \(3\) collecting keys/indices into a Vec before iterating to avoid borrowing the collection during mutation.
Journey Context:
Developer writes a method that calls another method on \`self\` while holding a mutable reference, or tries to \`push\` to a \`Vec\` while iterating over it. The compiler points to the second mutable borrow with a note showing the first borrow occurs earlier. Developer tries to wrap the first borrow in a block \`\{\}\` to limit its scope, but the borrow still lives until the end of the block because the return value or a guard extends it. They attempt to use \`Cell\` or \`RefCell\` to bypass the checker, triggering runtime panics. Eventually, they realize they must either collect keys to modify first using \`.keys\(\).cloned\(\).collect::>\(\)\`, use \`Vec::retain\`, or restructure the struct into sub-structs so they can mutably borrow field \`a\` while immutably borrowing field \`b\` via pattern matching \`let MyStruct \{ a, b \} = self;\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:12:35.855210+00:00— report_created — created