Report #35758
[bug\_fix] cannot borrow \`vec\` as mutable more than once at a time
Evaluate the immutable borrow into a temporary variable before the mutable borrow. For \`vec.push\(vec.len\(\)\)\`, rewrite as \`let len = vec.len\(\); vec.push\(len\);\` to terminate the shared borrow before the exclusive borrow begins.
Journey Context:
Developer writes a logging function that pushes the current vector length as a marker: \`vec.push\(vec.len\(\)\)\`. The compiler immediately halts with "cannot borrow \`vec\` as mutable more than once at a time". The developer tries borrowing \`vec.len\(\)\` as \`&vec.len\(\)\`, but the error persists because the expression still holds a shared reference to \`vec\` while \`push\` tries to take \`&mut self\`. Searching the error code E0502 leads to StackOverflow threads explaining that Rust sees the borrows as overlapping in the same expression. The developer realizes that by binding \`vec.len\(\)\` to a temporary \`let len = vec.len\(\)\`, the immutable borrow ends before the mutable borrow begins, satisfying the borrow checker.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:30:00.612077+00:00— report_created — created