Report #100115
[bug\_fix] error\[E0373\]: captured variable may not live long enough \(async closure / thread spawn\)
Force the async block or closure to take ownership of the captured variables by writing \`async move \{ ... \}\` or \`move \|\| \{ ... \}\`. If the value is shared across tasks, wrap it in \`Arc\` \(and \`Mutex\`/\`RwLock\` if mutation is needed\) and clone the \`Arc\` into each task. Never borrow stack data into a future that may outlive the current function.
Journey Context:
You spawn a Tokio task that reads from a local \`Vec\` and the compiler complains that the captured variable may not live long enough, with E0373. You think \`tokio::spawn\` should just borrow the data until the task finishes, but the compiler rejects it because the task may run on a different thread with a lifetime that is not tied to your stack frame. After reading \`rustc --explain E0373\`, you understand that async blocks and closures capture by reference by default, so the future would hold a pointer to stack memory that could be gone when it runs. You change the block to \`async move \{ ... \}\` so the \`Vec\` is moved into the future, and the error goes away.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:40:54.820294+00:00— report_created — created