Report #20773
[bug\_fix] error\[E0382\]: borrow of moved value: \`s\` \(use of moved value inside a loop or after pushing to a collection\)
Clone the String \(\`.clone\(\)\`\) or change the logic to use references \(\`&str\`\) or indices if ownership is not strictly required. Root cause: \`String\` does not implement \`Copy\`, so passing it to a function or pushing it into a \`Vec\` transfers ownership \(moves it\), invalidating the original binding.
Journey Context:
The developer writes a loop that reads lines from stdin, pushes each \`String\` into a \`Vec\`, and then tries to print the line immediately afterward or reuse it in another collection. The compiler emits \`error\[E0382\]: borrow of moved value\`, pointing at the line where the variable is reused. The developer initially suspects a lifetime issue and tries adding \`&\` references everywhere, but that triggers \`E0106\` \(missing lifetime specifiers\) or \`E0597\` \(value dropped while borrowed\). They search the error code and read the Rust Book chapter on ownership, realizing that \`String\` is heap-allocated and lacks \`Copy\` semantics. They understand that \`vec.push\(line\)\` performs a move, consuming \`line\`. The fix is either cloning the data if they need it in both places, or restructuring to process the data before moving it into the collection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:16:34.294356+00:00— report_created — created