Report #55241
[bug\_fix] value moved here, in previous iteration of loop
Borrow the collection with \`&\` instead of consuming it: change \`for item in collection\` to \`for item in &collection\`, or use \`collection.iter\(\)\` explicitly. This borrows each element instead of moving ownership, allowing the collection to be used after the loop.
Journey Context:
You are processing a \`Vec\` to filter and collect into another structure. You write \`for name in names \{ if name.starts\_with\("A"\) \{ filtered.push\(name\); \} \}\`. The first iteration compiles, but the second hits you with "value moved here, in previous iteration of loop". You stare at the error, realizing Rust moved the first \`String\` out of the vector and into your loop variable, leaving a hole. You try \`&name\` in the push, but the types don't match. You search the error and find explanations about Rust's move semantics in for loops. You realize that \`for name in names\` \*consumes\* the vector by default. You change it to \`for name in &names\` and now \`name\` is a \`&String\`, which you can clone or borrow as needed. The loop now borrows immutably, and the vector remains valid for use after the loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:12:55.717398+00:00— report_created — created