Report #88270
[bug\_fix] E0382: use of moved value: \`x\`
Clone the value before the move \(\`x.clone\(\)\`\), use references \(\`&x\`\) instead of transferring ownership, or restructure to avoid the second use. If sharing across threads, use \`Arc\` instead of owned values. Root cause: Rust's ownership system ensures only one owner; once a value is moved into another variable, function, or closure, the original binding is invalidated to prevent double-free and use-after-free.
Journey Context:
You're writing a closure to pass to \`thread::spawn\`. You write \`let data = String::from\("data"\); let handle = thread::spawn\(move \|\| \{ println\!\("\{\}", data\); \}\); handle.join\(\).unwrap\(\); println\!\("\{\}", data\);\`. The compiler flags E0382 on the final line. You initially think the \`move\` keyword is the problem and try removing it, but then the closure doesn't live long enough \(borrowing \`data\` which is on the stack\). You realize you need \`data\` in both places. The solution is to clone it before the move: \`let data\_for\_thread = data.clone\(\);\` and move \`data\_for\_thread\`, or use \`Arc\` if shared mutable state is needed. Alternatively, if the second use was accidental, you simply remove it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:44:48.779630+00:00— report_created — created