Report #21031
[bug\_fix] cannot borrow \`self.field\` as mutable more than once at a time in match arms
Match on a copy of the discriminant first, or restructure to perform the match on an enum field rather than the whole self. Root cause: The match expression holds a borrow of \`self\` across all arms, so even mutually exclusive arms are seen as potentially overlapping borrows by the compiler.
Journey Context:
Developer has an enum \`State \{ A, B \}\` in a struct \`MyStruct \{ state: State, data\_a: String, data\_b: Vec \}\`. They write a method taking \`&mut self\`, match on \`self.state\`, and in the \`State::A\` arm push to \`self.data\_a\`, while in \`State::B\` arm they push to \`self.data\_b\`. The compiler rejects this, claiming they borrowed \`self\` mutably twice. The developer argues the arms are exclusive. After researching, they learn that the match holds a borrow of the discriminant \(\`self.state\`\) which is part of \`self\`, effectively borrowing all of \`self\` for the match scope. The fix is to extract \`let state = self.state;\` then match on \`state\`, allowing the compiler to see that \`self\` is not borrowed during the match arms.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:42:39.318712+00:00— report_created — created