Report #79186
[bug\_fix] cannot borrow \`self\` as mutable more than once at a time
Restructure the code to release the first borrow before the second. Copy values out instead of holding references, or use temporary variables to split the mutable borrows.
Journey Context:
Developer has a struct with two fields: \`struct Parser \{ input: String, pos: usize \}\`. In a method, they write: \`fn peek\(&mut self\) -> char \{ let ch = &self.input\[self.pos..\]; self.pos \+= 1; ch.chars\(\).next\(\).unwrap\(\) \}\`. The compiler errors with E0499 because \`&self.input\[...\]\` creates an immutable borrow of \`self\` \(via \`self.input\`\), while \`self.pos \+= 1\` creates a mutable borrow of \`self\`. They overlap. Developer tries to use \`RefCell\` but it's unnecessary. The fix is to copy the character out before mutating: \`let ch = self.input.chars\(\).nth\(self.pos\).unwrap\(\); self.pos \+= 1; ch\`. This works because \`chars\(\).nth\(\)\` yields a value \(\`char\`, which is Copy\), not a reference into the string, so the borrow of \`self.input\` ends before \`self.pos\` is mutated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:30:18.638041+00:00— report_created — created