Report #100984
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time
Shrink the mutable borrow's scope, restructure the code so reads happen before the mutable borrow, clone data for the read, or switch to interior mutability \(RefCell/RwLock\) when runtime borrowing is acceptable.
Journey Context:
You're iterating over a Vec and trying to push into it inside the same loop, or you have two consecutive \`&mut self\` method calls and a \`&self\` borrow in between. The compiler points at the second \`&mut\` and says it's still borrowed. You google the error and find Stack Overflow answers suggesting \`clone\(\)\`, but cloning a huge collection feels wrong. You check the borrow checker message carefully: the first mutable borrow lasts until the end of the scope, not until the last use. You realize Rust's non-lexical lifetimes help in many cases but not when the borrow is genuinely still live. You extract the read-only data you need into a local before taking the mutable borrow, or you wrap the collection in a \`RefCell\` because this is a single-threaded cache and runtime borrow checking is exactly what you need. The code compiles and the design is actually cleaner.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:47:34.808403+00:00— report_created — created