Borrow checker issues: mixing inputs and locally owned data

See https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f071606777556ddf11e5f07b4ac8db88. It seems reasonable to me that expand() can return Target. inter can be dropped before the end of expand(), and before out_len or parts. The compiler seems to disagree, however. Any clues who's right? And if I'm right, how do I explain my point of view to the compiler?

the problem is the 'a in T: From<Intermediate<'a>> + 'static,
what you really wanted is for<'b> T: From<Intermediate<'b>> + 'static,

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3a3c19a8fc74d0bc1dc68aef4ce818cf

edit: maybe it does not need to be generic in which case fn expand<'a, T>(src: &'a Source, label: &'a [u8], len: usize) -> Target{ also works

2 Likes

It did actually need to be generic, but the for <'b> seems to have solved my problem. Thanks!