Hi,
I recently came across this error:
fn foo() -> &str {
return &"bar";
}
That required me to add a 'static as such:
fn foo() -> &'static str {
return &"bar";
}
This is fine, except it is confusing why the compiler doesn't do this automatically. In particular, it seems to me that zero-parameter functions that returns a reference can only possibly return 'static references, so there should be a rule like the lifetime elision rules that adds the 'static in. Am I missing something?
And apologies if this is answered elsewhere -- the various searches I could think of produced no results.
Thank you.