Report #11362
[bug\_fix] cannot return reference to local variable \`s\`
Return the owned \`String\` \(or \`Vec\`\) instead of a slice or reference, or accept a \`&mut String\` buffer parameter to write into.
Journey Context:
Developer writes a helper function to trim or format a string, trying to be 'zero-cost' by returning \`&str\`. They write \`let s = format\!\("..."\); &s\[..\]\` and the compiler rejects it with a lifetime error. They try adding explicit \`'static\` lifetimes, which fails because the data is stack-allocated. They search StackOverflow and realize that local variables are dropped at the end of the function, making any reference to them a dangling pointer. The 'aha' moment comes when they understand that Rust's ownership system prevents use-after-free bugs at compile time. They refactor to return the \`String\` directly, accepting the heap allocation as necessary, or redesign the API to take a mutable buffer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:11:38.711257+00:00— report_created — created