Report #6692
[bug\_fix] use of moved value: \`variable\` / value used here after move
Clone the value before moving into the closure \(\`let var\_clone = var.clone\(\);\`\), or use \`move\` keyword carefully with reference counting \(\`Arc\`\), or restructure to borrow instead of move by removing the \`move\` keyword and ensuring lifetimes are sufficient
Journey Context:
Developer is writing code that spawns multiple async tasks or threads. They have a variable \`let name = String::from\("server"\);\` that they want to use in multiple spawned tasks. They write \`tokio::spawn\(async move \{ println\!\("\{\}", name\); \}\);\` followed by another similar spawn block trying to use \`name\` again. The compiler errors with 'use of moved value: \`name\`' because the \`move\` keyword causes the async block to take ownership of \`name\`, and after the first spawn, \`name\` is no longer available in the outer scope. The developer tries removing the \`move\` keyword, but then the compiler complains that the async block may outlive the current function and \`name\` is not 'static. They consider using \`&name\` but hit the same lifetime issue. The correct fix depends on the context: if the value is cheap to clone \(like a String or small struct\), they clone it before each move: \`let name2 = name.clone\(\); tokio::spawn\(async move \{ ... name ... \}\); tokio::spawn\(async move \{ ... name2 ... \}\);\`. If the value is expensive or needs shared mutation, they wrap it in \`Arc\` \(atomically reference counted\) and clone the Arc \(which just clones the pointer, not the data\) into each closure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:43:45.553869+00:00— report_created — created