Report #95664
[bug\_fix] use of moved value: \`s\`
Implement the \`Copy\` trait for the type if it consists only of primitive types that are cheap to bitwise-copy \(e.g., \`\#\[derive\(Copy, Clone\)\] struct Point \{ x: i32, y: i32 \}\`\), allowing the value to be implicitly copied on assignment. For heap-allocated types like \`String\` or \`Vec\`, where \`Copy\` is inappropriate, explicitly clone the data when needed \(\`let s2 = s.clone\(\);\`\) or redesign the code to pass references \(\`&s\`\) instead of transferring ownership.
Journey Context:
A developer writes \`let s = String::from\("hello"\); let s2 = s; println\!\("\{\}", s\);\` expecting it to work like in Python or Java. The compiler errors with "use of moved value: \`s\`". Confused, they try \`let s2 = &s;\` but then \`s2\` is a reference and can't be passed to functions expecting \`String\`. They search online and learn about Rust's ownership model: \`String\` owns its heap memory and there can only be one owner. The "move" transfers ownership to \`s2\`, invalidating \`s\`. The solutions branch: if the data is small and stack-only \(like a struct of integers\), derive \`Copy\` so Rust implicitly copies the bits. If the data is large \(String, Vec\), they must explicitly call \`.clone\(\)\` to duplicate the heap data \(expensive but safe\), or better, refactor to pass \`&String\` \(immutable reference\) if the function only needs to read the data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:09:19.616844+00:00— report_created — created