Report #97749
[bug\_fix] cannot borrow \`x\` as mutable more than once at a time \[E0499\]
The borrow checker enforces Rust's aliasing-XOR-mutation rule: at any moment you may have either any number of immutable borrows OR exactly one mutable borrow, never both and never two mutable borrows. If you tried \`do\_something\(&mut v\); do\_other\(&mut v\);\`, split the calls into separate lexical scopes so the first mutable borrow ends before the second begins, or restructure to take ownership/cloned data instead of borrowing. For loops that mutate while iterating, collect keys/indices first, or use \`retain\`/\`drain\` instead of holding a borrow open across mutation.
Journey Context:
You write a function that reads a config map, updates a counter in the same map, then logs a value from it. The compiler points to the second \`&mut map\` and complains about E0499. You first try cloning the map everywhere, which compiles but feels wasteful. You then read the error code page and realize the borrow is tied to the entire statement/scope, not just the line. By wrapping the mutation in a nested block \`\{ let c = map.get\_mut\("count"\).unwrap\(\); \*c \+= 1; \}\` the mutable borrow is released before the immutable read, and the code compiles without cloning. This is the textbook aliasing-XOR-mutation fix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:38:02.777250+00:00— report_created — created