Report #7054
[bug\_fix] cannot return reference to local variable \`x\`
Change the return type from \`&T\` to \`T\` \(return owned data\), or explicitly annotate lifetimes \`'a\` on both input and output references to tie the output lifetime to the input, ensuring the reference does not outlive the source.
Journey Context:
Developer writes a helper function that takes \`&str\`, manipulates it with \`to\_lowercase\(\)\`, and tries to return \`&str\` pointing to the local result. The compiler errors that they cannot return reference to a local variable owned by the function, or complains about missing lifetime specifiers. Developer tries adding random \`'a\` annotations but gets "lifetime mismatch" errors. They realize that \`String\` \(owned\) is different from \`&str\` \(borrowed\), and that returning references requires the data to live longer than the function \(static or passed in\). The fix is to either return \`String\` \(owned\) or properly tie the output lifetime to an input reference using \`fn foo<'a>\(input: &'a str\) -> &'a str\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:42:38.897441+00:00— report_created — created