Report #46520
[bug\_fix] error\[E0382\]: use of moved value: \`s\`
Clone the value if cheap \(\`s.clone\(\)\`\), use references to avoid moving \(\`&s\`\), or restructure the code to avoid using the value after transfer. The root cause is that \`String\` \(and most non-Copy types\) are moved by default when passed to functions or assigned to variables, invalidating the original binding.
Journey Context:
Developer writes a function that takes ownership of a \`String\` to process it, then wants to use that same string later in the main function for logging. They call \`process\_data\(s\)\` where \`s: String\`, then try \`println\!\("Processed: \{\}", s\)\`. The compiler throws E0382, pointing to the second use of \`s\`. Developer first tries to fix it by making the function take \`&String\`, which works but requires changing the function signature. Or they realize they can clone the string: \`process\_data\(s.clone\(\)\)\` to keep the original. Alternatively, they restructure to return the string back from the function if the function doesn't need to consume it permanently. The key realization is understanding that \`String\` doesn't implement \`Copy\`, so assignment moves ownership rather than copying the data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:33:25.152340+00:00— report_created — created