Report #103788
[bug\_fix] error\[E0597\]: \`s\` does not live long enough; borrowed value does not live long enough
Return an owned value \(\`String\`, \`Vec\`, etc.\) instead of a reference to data created inside the function. If a reference must be returned, the referenced data must be owned by the caller and passed in as an argument so it outlives the return value.
Journey Context:
Coming from Python, I wrote \`fn host\(\) -> &str \{ let s = String::from\("localhost"\); &s \}\` and expected the string to stay alive because the caller used the reference. Rust gave E0597. I tried adding a lifetime annotation \`-> &'a str\`, but that only made the error worse because there was no input lifetime to tie it to. The compiler was right: \`s\` is dropped when \`host\` returns, so any reference would dangle. I changed the return type to \`String\` and returned \`s\` directly, transferring ownership. The API is simpler and the reference is impossible to misuse.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:42:30.476754+00:00— report_created — created