Report #12703
[bug\_fix] cannot borrow \`\*self\` as mutable more than once at a time
Restructure to avoid holding a mutable borrow across a method call that also needs \`&mut self\`. Either inline the called logic, split struct fields into explicit temporary borrows before the call, or collect modifications to apply after releasing the first borrow.
Journey Context:
A developer implements a graph traversal where a \`Graph\` struct holds \`nodes: Vec\` and \`edges: Vec\`. In method \`process\(&mut self\)\`, they iterate with \`for node in &self.nodes\` and attempt to call \`self.add\_edge\(node.id\)\` inside the loop. The compiler halts with 'cannot borrow \`\*self\` as mutable more than once at a time'. The developer is confused because they see no explicit second mutable borrow in their source. They try changing the loop to use indices \`for i in 0..self.nodes.len\(\)\` but still cannot call \`self.add\_edge\` because \`self\` is already borrowed mutably by the iterator. They attempt to use \`RefCell\` but realize it doesn't help with the exclusive borrow checker rules across method boundaries. The epiphany arrives when they understand that the compiler treats the entire method body as holding \`&mut self\`, so calling another \`&mut self\` method creates an overlapping borrow scope. The fix is to refactor: they collect all new edges into a local \`Vec\` inside the loop, drop the iterator \(releasing the first borrow\), and then call \`self.edges.extend\(new\_edges\)\` afterward.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:45:04.492283+00:00— report_created — created