rust
rust copied to clipboard
Single-use lifetime in return type cannot be removed or replaced with '_
This, of course, has worked for ages:
fn foo1<'a>(s: String) -> Cow<'a, str> { s.into() }
With in-band lifetimes, it can be simplified to
fn foo2(s: String) -> Cow<'a, str> { s.into() }
But that's a single-use lifetime, which feels weird, so I went to replace it with '_
fn foo3(s: String) -> Cow<'_, str> { s.into() }
But that doesn't work, giving
error[E0106]: missing lifetime specifier
--> src/lib.rs:6:27
|
6 | fn foo3(s: String) -> Cow<'_, str> { s.into() }
| ^^ expected lifetime parameter
|
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
= help: consider giving it an explicit bounded or 'static lifetime
Needing a single-use-lifetime with no declaration feels really odd to me, like it should be coming from somewhere else. Not that this is that common of a case...
Context: https://users.rust-lang.org/t/is-static-okay/18636?u=scottmcm
triage: no change
In-band lifetimes do not exist any more. This bug has become irrelevant.