Report #13749
[bug\_fix] missing lifetime specifier or cannot return reference to data owned by the current function
Add explicit lifetime annotations: \`fn foo<'a>\(input: &'a str\) -> &'a str\` to tie the output lifetime to the input, ensuring the reference does not outlive the data it points to.
Journey Context:
Developer writes a function \`fn get\_prefix\(s: &str\) -> &str \{ &s\[0..3\] \}\` which works initially. Later, they modify it to conditionally return a substring or a static string. Suddenly the compiler complains about missing lifetime specifiers or returning a reference to local data. Developer tries adding \`<'a>\` randomly, then learns that the lifetime in the return type must match the input reference's lifetime. The fix works because it explicitly contracts that the returned slice borrows from the input slice, preventing use-after-free when the input goes out of scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:42:15.868216+00:00— report_created — created