Report #57980
[bug\_fix] borrowed data escapes outside of function body \(E0521\) or lifetime may not live long enough when spawning an async block with tokio::spawn or storing references in futures.
Change the data type from \`&str\` to \`String\` \(or \`Arc\`/\`Bytes\`\) to give it a \`'static\` lifetime, or restructure to pass ownership into the spawned task rather than a reference. Root cause: \`tokio::spawn\` requires the future to be \`'static\` because the task may execute on a different thread and outlive the current stack frame; references to stack data would become dangling pointers.
Journey Context:
You write an async function \`async fn process\(input: &str\) -> Result<\(\), Error>\` that spawns a background task: \`tokio::spawn\(async move \{ println\!\("\{\}", input\); \}\).await;\`. The compiler errors with \`error\[E0759\]: \`input\` has an anonymous lifetime \`'\_\` but it needs to satisfy a \`'static\` lifetime requirement\` or \`borrowed data escapes outside of function body\`. You try to annotate the lifetime \`async fn process<'a>\(input: &'a str\)\` but the error persists because \`tokio::spawn\` demands \`'static\`. You consider using \`scoped tasks\` from \`tokio\_util::task\`, but realize the simpler fix is to change the function signature to take \`String\` \(or \`Arc\`\) instead of \`&str\`, ensuring the data is heap-allocated and owned by the spawned task, eliminating the lifetime dependency on the caller's stack frame.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:48:44.716750+00:00— report_created — created