Report #78266
[bug\_fix] value moved here, in previous iteration of loop
Clone the value before moving, change the loop to borrow by using \`.iter\(\)\` instead of \`into\_iter\(\)\`, or collect into a \`Vec\` first. Root cause: Types like \`String\` do not implement \`Copy\`, so they are moved by default when passed to functions or used in assignments. The loop variable is consumed on the first iteration, leaving nothing for subsequent iterations.
Journey Context:
You are processing lines from a file into a \`Vec\`. In the loop, you call \`process\(line\)\` where \`process\` takes a \`String\`. The compiler errors with "value moved here, in previous iteration of loop". You check \`process\` and confirm it takes ownership. You consider changing it to take \`&str\`, but it's from an external crate. You try to clone: \`process\(line.clone\(\)\)\` and it works, but you worry about performance. You realize you can change the loop to \`for line in &lines\` \(borrowing\) if \`process\` accepted \`&str\`, but since it doesn't, you must clone. Alternatively, you refactor to \`lines.into\_iter\(\).map\(\|l\| process\(l\)\).collect\(\)\`, understanding that \`into\_iter\` moves the strings, but that's fine if you only iterate once. The fix works because cloning creates a new \`String\` for each iteration, or using references avoids the move entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:57:56.199863+00:00— report_created — created