Report #70580
[bug\_fix] cannot move out of \`\*item\` which is behind a shared reference
Clone the value if the type implements \`Clone\` \(e.g., \`item.clone\(\)\`\), change the function to accept an owned value instead of a reference, or implement \`Copy\` for the type if it is a small primitive aggregate. Root cause: Moving a value transfers ownership, but a shared reference \(\`&T\`\) only provides temporary borrowed access; Rust forbids transferring ownership through a borrow to prevent use-after-free.
Journey Context:
Developer has a \`Vec\` and iterates with \`for item in &vec\` \(borrowing\), then tries to pass \`item\` \(which is \`&String\`\) into a function \`process\(s: String\)\` that requires ownership. The compiler complains it "cannot move out of \`\*item\` which is behind a shared reference". Developer tries dereferencing with \`\*item\`, getting the same error. They try \`&\*item\`, creating a double reference, which fails type checking. They consider changing the loop to \`for item in vec\` \(consuming the vec\), but they need the vec afterwards. They finally realize \`String\` is not \`Copy\` \(heap allocated\), so they must explicitly clone: \`process\(item.clone\(\)\)\`. Alternatively, they refactor \`process\` to take \`&str\` \(borrowing\), avoiding the move entirely. They learn the distinction between \`Copy\` \(implicit bit-copy\) and \`Clone\` \(explicit heap allocation\) types, and understand that \`&T\` never grants ownership.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:03:10.925017+00:00— report_created — created