I'm having difficulty understanding some errors that seem related to async and await boundaries.
Here's my example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=bfec125338bada5ada716417c7b41cab
Unfortunately I haven't been able to reduce it further.
error[E0597]: `foo` does not live long enough
--> src/main.rs:53:25
|
46 | pub async fn run_filters(&'a self, mut foos: Vec<Foo<'a>>) -> Vec<Foo<'a>> {
| -------- lifetime `'1` appears in the type of `self`
...
53 | if func(&foo).await {
| -----^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `foo` is borrowed for `'1`
...
56 | }
| - `foo` dropped here while still borrowed
I don't understand how the borrowed value doesn't live long enough when the function is awaited immediately. I also cannot see where the '1 lifetime is from. I'd like to understand this better.
error[E0515]: cannot return value referencing local variable `self`
--> src/main.rs:131:13
|
126 | FooDelay::Seconds(x) => self.run(x).await
| ---- `self` is borrowed here
...
131 | Some(foos[0])
| ^^^^^^^^^^^^^ returns a value referencing data owned by the current function
The only reference being returned (contained within the Foo struct) is one that was passed into FooQuery to begin with. I have assumed the borrow of self would be completed after the await, but perhaps that assumption is false?