Report #36615
[bug\_fix] cannot borrow \`\*self\` as mutable more than once at a time \(E0499\)
Restructure the code to avoid holding a mutable borrow across method calls. Split the borrows by extracting fields into local variables: \`let field = &mut self.field; let other = &mut self.other;\` \(partial borrowing\). Alternatively, use interior mutability \(\`RefCell\`\) if shared ownership is required, or reorganize logic to drop the first borrow before the second.
Journey Context:
Developer has \`struct Parser \{ input: String, pos: usize \}\`. They write \`fn peek\(&mut self\) -> &str \{ &self.input\[self.pos..\] \}\` and \`fn advance\(&mut self\) \{ self.pos \+= 1; \}\`. In another method \`fn process\(&mut self\)\`, they write \`let slice = self.peek\(\); self.advance\(\); println\!\("\{\}", slice\);\`. Compiler errors on \`self.advance\(\)\` saying cannot borrow \`\*self\` as mutable more than once. The rabbit hole involves trying scopes \`\{ let slice = self.peek\(\); \}\` which fails because the returned \`&str\` lifetime is tied to \`&mut self\`. The developer realizes \`peek\` holds a mutable borrow of \`self\` \(and thus \`self.input\`\) for as long as the return value exists. The fix works by splitting the struct into independent mutable borrows: \`let input = &mut self.input; let pos = &mut self.pos;\` then operating on \`input\` and \`pos\` separately, or by cloning the data \(\`let slice = self.peek\(\).to\_string\(\);\`\) to drop the borrow before the next call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:56:21.559298+00:00— report_created — created