Report #99164
[bug\_fix] error\[E0308\]: mismatched types: expected \`String\`, found \`&str\`
Convert the \`&str\` to an owned \`String\` with \`.to\_owned\(\)\` or \`.to\_string\(\)\` when the function expects an owned value, e.g. \`let s = slice.to\_string\(\); func\(s\);\`. If the function should accept either, change its parameter to \`&str\` or \`impl AsRef\` to avoid unnecessary allocations.
Journey Context:
You passed a string literal or borrowed slice to a function whose signature takes \`String\`. The compiler reports E0308 because \`String\` is an owned heap-allocated type while \`&str\` is a borrowed view. You first try adding \`&\` in front of the literal, which only inverts the error. The robust fix depends on ownership needs: if the function must own the string \(e.g. to store it in a struct\), call \`.to\_string\(\)\` at the call site; if the function only reads the string, change the parameter to \`&str\` so callers do not need to allocate. This is one of the most frequent onboarding errors in Rust and stems from the language distinguishing owned and borrowed string types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:40:54.773286+00:00— report_created — created