Report #60867
[bug\_fix] use of moved value: \`my\_string\` \[E0382\] or value used here after move
Either \`.clone\(\)\` the value before moving if you need the original later, or change the function signature to accept a reference \`&String\` or \`&str\` instead of owned \`String\` to avoid taking ownership. The root cause is that \`String\` \(and most heap-allocated types\) does not implement the \`Copy\` trait, so assigning or passing them to functions moves ownership rather than copying the data; once moved, the original variable is invalidated to prevent use-after-free and double-free errors.
Journey Context:
Developer writes a function \`fn greet\(name: String\) \{ println\!\("Hello, \{\}", name\); \}\`. In \`main\`, they have \`let name = String::from\("Alice"\); greet\(name\); println\!\("Again, \{\}", name\);\`. The compiler errors on the second \`println\!\` with E0382 saying \`name\` was moved in the call to \`greet\`. Developer is confused because in other languages \(C\+\+, Java, Python\) this would just work \(either copy or reference\). They try to fix it by changing \`greet\` to take \`&String\`, but they wrote the signature expecting an owned \`String\` because they thought they needed to consume it. They read the Rust Book chapter on Ownership and learn about the \`Copy\` trait. They realize \`String\` cannot be \`Copy\` because it owns heap memory; if both \`greet\` and \`main\` had ownership, they'd both try to free the same memory. They decide they don't actually need ownership in \`greet\`, so they change the signature to \`fn greet\(name: &str\)\` and call it with \`greet\(&name\)\`. This works because \`main\` retains ownership of \`name\` and \`greet\` just views it temporarily. The fix works because it respects ownership rules: either clone to duplicate the data \(giving each owner their own copy\) or borrow to share temporary access without transferring ownership.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:38:57.402601+00:00— report_created — created