Report #24874
[bug\_fix] async block may outlive the current function, but it borrows \`x\`, which is owned by the current function
Ensure the async block takes ownership of the data rather than borrowing it, or ensure the data lives for \`'static\`. Wrap the data in an \`Arc\` \(if shared\) or move it directly into the block with \`async move\`. If the data is local to the function and cannot be moved, refactor to use message passing \(channels\) instead of spawning a task that borrows local stack data.
Journey Context:
Developer writes an async function that processes a request: \`async fn handle\(req: Request\) \{ let data = load\_data\(\); tokio::spawn\(async \{ process\(&data\).await \}\); \}\`. The compiler errors stating the async block may outlive the current function but borrows \`data\`. The developer tries \`async move \{ process\(&data\).await \}\` but the error persists because \`process\` takes a reference, so \`data\` is still borrowed by the future even with \`move\`. The developer tries cloning \`data\` before the block but the type doesn't implement \`Clone\`. They consider using \`unsafe\` to extend lifetimes. Eventually, they realize they must ensure the future owns the data, not borrows it. They change \`process\` to take \`Arc\` or change the signature to take ownership. They wrap \`data\` in \`Arc::new\(data\)\` and use \`Arc::clone\` inside the async block, ensuring the data lives as long as the task.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:09:36.177769+00:00— report_created — created