Report #5386
[bug\_fix] error\[E0308\]: mismatched types: expected struct \`String\`, found \`&str\`
Convert \`&str\` to \`String\` using \`.to\_string\(\)\` or \`.into\(\)\`, or change the target type to \`&str\` to accept borrowed strings. Root cause: \`String\` is an owned heap-allocated buffer, while \`&str\` is a borrowed slice; Rust distinguishes owned vs borrowed strictly.
Journey Context:
Developer has a literal \`let name = "Alice";\` and tries to pass it to \`fn greet\(name: String\)\`. Compiler complains about type mismatch. Developer tries \`&name\` thinking that's how you pass by reference, but that's \`&&str\`. They try \`String::from\(name\)\` which works, then discover \`name.to\_string\(\)\` is idiomatic. Later, they refactor the function to accept \`&str\` instead, realizing it doesn't need ownership, and learn that \`String\` coerces to \`&str\` via Deref coercion, allowing the function to accept both literals and owned strings seamlessly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:11:56.886231+00:00— report_created — created