E0499: Cannot Borrow as Mutable More Than Once in Async Closures
An async block or FnMut closure keeps a mutable borrow alive past the point you expected. Scoping, split_at_mut and the Arc<Mutex> decision.

Introduction & Quick Summary
Symptom. The borrow checker rejects code that looks obviously correct: error[E0499]: cannot borrow \state` as mutable more than once at a time, often on two calls that never touch the same field, or on an asyncblock that captures&mutand is passed tojoin!. In async code the same underlying mistake also surfaces as error: captured variable cannot escape `FnMut` closure bodyorfuture cannot be sent between threads safely`.
Cause. Rust guarantees one live mutable reference to a place at a time. Non-lexical lifetimes end a borrow at its last use — but an async block, a future stored in a variable, or a closure capture keeps the borrow alive until the future is dropped or the closure last runs. In a closure, a captured &mut cannot be returned from an FnMut call, because the closure may run again while the first future still holds the reference.
Fix. Shorten the borrow to what it actually needs: sequential awaits instead of two live futures, a scoped block around a guard, destructuring so the compiler sees disjoint fields, split_at_mut or iter_mut for two elements of a slice, and Arc<Mutex<_>> (or tokio::sync::Mutex) only when the value is genuinely shared across tasks. Moving a guard across .await is a threading bug dressed as a borrow error; the fix is the scope, not a clone().
Core Mechanics, Signatures & Reproducible Setup
E0499 is reported per place, not per type. Two calls to methods that take &mut self on the same value keep two mutable borrows alive for as long as their results are used:
struct Conn { buf: Vec<u8> }
impl Conn {
async fn send(&mut self, frame: &str) -> usize {
self.buf.extend_from_slice(frame.as_bytes());
self.buf.len()
}
}
async fn broken(conn: &mut Conn) -> (usize, usize) {
let a = conn.send("ping"); // mutable borrow of *conn starts
let b = conn.send("pong"); // E0499: second mutable borrow
tokio::join!(a, b) // both futures alive here
}The compiler's suggestion is usually to make one borrow end earlier. The smallest correct version awaits the first future before creating the second:
async fn fixed(conn: &mut Conn) -> (usize, usize) {
let a = conn.send("ping").await;
let b = conn.send("pong").await;
(a, b)
}For a real reproducer, cargo new --lib eq499 && cd eq499 with tokio = { version = "1", features = ["full"] } in Cargo.toml; cargo check prints E0499 with the two spans, which is the fastest way to see that the borrow starts at the method call rather than at the join!.
Key Comparison Table
The borrow-family errors look alike and mean different things.
| Error | Meaning | Typical fix |
|---|---|---|
| E0499 | Two mutable borrows of one place | End the first borrow before the second |
| E0502 | Mutable borrow while an immutable one is live | Clone the read value, or scope the borrow |
| E0500 | Closure borrows a variable the function also borrows | Pass the value in, or use move |
| E0505 | Cannot move out while borrowed | Drop the borrow first |
| E0597 | Borrowed value does not live long enough | Own the value, or extend the scope |
| E0716 | Temporary dropped while borrowed | Bind it to a let |
captured variable cannot escape FnMut | Closure would return a borrow of its own capture | Own the data, or return impl Future from async move |
The strategies for shared mutable state trade compile-time safety for design constraints:
| Strategy | Borrow error at compile time | Cost | When to use |
|---|---|---|---|
Sequential awaits | Yes | Latency | Requests that must be ordered anyway |
| Disjoint field borrows / destructuring | Yes | None | Struct with independent parts |
split_at_mut, iter_mut, chunks_mut | Yes | None | Two elements of one slice |
Arc<Mutex<T>> | No | Lock contention, poisoning | Genuinely shared state |
tokio::sync::Mutex | No | Async lock, allocation | Shared across tasks with .await inside |
Rc<RefCell<T>> | No | Runtime panic on double borrow | Single-threaded graphs |
| Clone the value | No | Memory | Small, cheap-to-copy state |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Two &mut self calls that must be concurrent
When the calls really do need to run concurrently, they cannot share one &mut connection. Either give each its own connection from a pool, or move the shared state into a structure that supports it:
// Each task owns its half of the state
let (tx, rx) = tokio::sync::mpsc::channel(64);
let a = { let rx = rx; tokio::spawn(async move { /* owns rx */ }) };Splitting a struct into independently owned parts is usually better than a mutex: the compiler then proves the tasks cannot interfere, instead of a lock serialising them at runtime.
2. Disjoint field borrows
The borrow checker understands fields as separate places, so two mutable borrows of different fields are fine — even when they are reached through the same struct reference, as long as the destructuring happens first:
struct Job { input: Vec<u8>, output: Vec<u8> }
fn run(job: &mut Job) {
let Job { input, output } = job; // two disjoint &mut
output.extend_from_slice(input); // compiles
}A method call (job.process()) borrows the whole Job and loses this ability; destructuring or free functions keep it.
3. The async block that captures &mut
An async block borrows by default and the future lives in a variable, so the borrow lasts until the future is dropped — often longer than the surrounding scope:
let fut = async { counter.increment().await }; // borrows counter mutably
counter.read(); // E0499 while fut is aliveTwo fixes, depending on intent: drop the future first (drop(fut);), or make the block own its data with async move and pass a clone or an Arc.
4. Holding a std::sync::MutexGuard across .await
This compiles until the future is sent to another thread, then fails with future cannot be sent between threads safely because MutexGuard is not Send. The borrow error and the Send error are the same mistake seen from two directions:
// Broken: guard alive across await
let mut guard = state.lock().unwrap();
let value = fetch().await;
guard.value = value;
// Fixed: keep the await outside the guard's scope
let value = fetch().await;
{
let mut guard = state.lock().unwrap();
guard.value = value;
}If the critical section genuinely needs to await, use tokio::sync::Mutex, whose guard is Send and intentionally does not implement Deref across threads.
5. FnMut closures that return futures
Option::map with an async closure, or for_each over a stream, cannot hand out a reference to a captured variable, because FnMut may be called again:
// Broken: returns a future borrowing the closure's capture
let collected: Vec<_> = items.iter().map(async |i| state.push(*i)).collect();Use a loop, which sequences the borrows, or async move with owned data per item, or futures::stream::iter(...).then(...) where each future owns its inputs:
for i in items.iter() {
state.push(*i).await; // one borrow at a time
}6. Two elements of one slice
Indexing mutably twice is the textbook E0499. The standard library provides the disjoint ways out:
let (left, right) = slice.split_at_mut(1);
left[0] = 1; right[0] = 2;
for pair in slice.chunks_mut(2) { pair[0] = pair[1]; }
// Since Rust 1.86: checked disjoint indexes, no panic path
if let Ok([a, b]) = slice.get_disjoint_mut([0, 2]) { *a += *b; }get_disjoint_mut returns Result, so an out-of-range or duplicated index is an error instead of a panic — useful in parsers where the index comes from input.
Common Compilation/Runtime Mistakes & Version Gotchas
- Reaching for
clone()to silence E0499. It compiles and quietly changes semantics: updates go to the copy. Prefer scoping, splitting, or an explicitArcwith a comment about sharing. - Assuming non-lexical lifetimes help across
.await. NLL ends borrows at last use; a future that is alive across anawaitis a use at that point, so the borrow continues. let _ = mutex.lock();. The guard is dropped immediately, releasing the lock before the section runs — a data race written as a one-liner. Bind it:let _guard = …;.- Edition 2021 closure capture vs 2024. Edition 2021 captures disjoint fields (RFC 2229); edition 2024 adds precise capturing (
impl Future + use<'_>) and drops the implicitBox<dyn Future>workarounds, so code that compiled withasyncblocks can fail after an edition change with new lifetime errors. tokio::join!as a fix. Joining two futures that borrow the same value mutably is exactly the reported error;join!changes scheduling, not aliasing.RefCellas an escape hatch.Rc<RefCell<T>>moves E0499 to a runtimealready borrowed: BorrowMutError, which is harder to trace and only appears on the path that hits it.- Trait objects hiding the borrow.
Box<dyn FnMut() -> impl Future>needs an explicit lifetime or owned captures; the error text names the closure rather than the trait, so read the span on the captured variable.
Related tools. Paste the failing snippet and the fixed one into the text diff tool to confirm the borrow was scoped rather than the logic changed, and when the connection whose borrow is disputed reads a JSON payload, run it through the JSON formatter first so the data shape is not part of the debugging problem.
Try matching browser tools
All toolsSmall utilities that fit Rust work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Rust guides
All Rust guidesRust Tokio: Blocking the Runtime and spawn_blocking Fixes
A synchronous call inside an async fn stops the worker that drives every other task on it, timers included. Detection, spawn_blocking, and the guard-across-await trap.
Rust: Future Cannot Be Sent Between Threads Safely in Tokio
spawn needs Send + 'static, and any non-Send value alive across an await breaks it. Shorten the guard, switch the lock, or move the work to a LocalSet.
Rust Unsafe: Raw Pointers, FFI Bindings, and Soundness Invariants
What unsafe actually unlocks, the five soundness contracts behind raw pointers, and the FFI rules for repr(C), CString and unwinding.
Rust Pin and Unpin: Memory Pinning, Self-Referential Structs, and Futures
Why a future must not move after polling starts, what Unpin opts out of, and how Box::pin, pin! and map_unchecked_mut express that guarantee.
More in Rust
All Rust guidesThe guides filed next to this one in Rust, in library order.