Report #38448
[bug\_fix] value moved here in previous iteration of loop \(E0382\)
Clone the value using \`.clone\(\)\` if the type implements \`Clone\`, or restructure to pass references instead of owned values. Root cause: Rust's ownership model moves non-Copy types by default; once moved into a collection or consumed in a loop iteration, the original binding is invalid.
Journey Context:
Developer writes a loop to collect \`String\` instances into a \`Vec\`. Inside the loop, they push a variable \`s\` of type \`String\` into the vector using \`vec.push\(s\)\`. On the second iteration, the compiler errors with "value moved here in previous iteration of loop". Developer attempts to change \`push\(s\)\` to \`push\(&s\)\` to avoid moving, but the type checker rejects \`&String\` where \`String\` is expected. Searching the error code E0382 leads to documentation explaining ownership. Developer applies \`.clone\(\)\` to the push argument as a quick fix, which works because it creates a new owned allocation, leaving the original \`s\` valid for the next iteration. Later, the developer refactors to use iterator methods like \`map\` and \`collect\` to avoid the explicit loop and clones, understanding that ownership transfer is a zero-cost abstraction for memory safety.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:00:55.199455+00:00— report_created — created