Report #10829
[bug\_fix] cannot borrow \`\*self\` as mutable more than once at a time \(E0499\)
Restructure to avoid holding a mutable reference across the second borrow. If methods operate on different fields, borrow the fields separately: \`let a = &mut self.field\_a; let b = &mut self.field\_b;\`. If the first borrow returns a reference that must survive, clone the data or temporarily remove it using \`std::mem::take\` or \`Option::take\`. Root cause: \`&mut self\` creates an exclusive borrow for the duration of its lifetime; calling another \`&mut self\` method or accessing overlapping fields creates a conflicting second exclusive borrow.
Journey Context:
A developer has a \`Cache\` struct with \`get\(&mut self, key: &str\) -> &Value\` and \`set\(&mut self, key: &str, val: Value\)\`. In an \`update\` method, they write \`let val = self.get\("key"\); self.set\("key", new\_val\);\`. The compiler errors with E0499, stating the first mutable borrow from \`get\` lasts until \`val\` is dropped, which is after the second \`set\` borrow. Developer tries \`drop\(val\)\` before \`set\`, but the borrow checker knows \`val\` still exists in scope. They try splitting into two scopes \`\{ let val = self.get\(...\); ... \} self.set\(...\)\` but this fails if \`val\` is needed after the set. They realize the architecture is flawed: you cannot hold a reference to cache data while mutating the cache. Fix is to clone the value: \`let val = self.get\("key"\).clone\(\);\` \(dropping the ref before set\) or using \`std::mem::take\` to temporarily extract the cache's contents.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:46:36.716973+00:00— report_created — created