Report #45266
[bug\_fix] use of moved value: \`value\` \(in a loop after move\)
Clone the value before the consuming operation if it is needed again later: \`let parsed = line.clone\(\).parse::\(\)?;\` or restructure to parse by reference if the API allows \(\`line.parse::\(\)\` doesn't move \`line\` actually, but consuming functions do\).
Journey Context:
Developer reads lines from a file into a \`String\` called \`line\` in a \`while let\` loop. Inside the loop, they call a function \`process\(line\)\` that takes ownership of \`String\` \(not \`&str\`\). Later in the same loop iteration, they try to print \`line\` for debugging or error context. The compiler throws E0382 'use of moved value'. Developer tries to make the function take \`&str\`, but the function signature is from an external crate and requires \`String\`. They consider making \`line\` mutable and using \`std::mem::take\`, but that's tricky. The rabbit hole reveals that ownership is linear; once moved, the variable is uninitialized. The fix works because \`clone\(\)\` creates a new allocation with the same data, leaving the original \`line\` valid for the remainder of the loop iteration. This is the idiomatic cost when you need both the consumed value and the original.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:26:48.631857+00:00— report_created — created