This is surprising because a lot of alterations to this code fixes the issue, for example replacing map(|x| *x) withcopied(), which is seemingly an equivalent replacement. Moreover, replacing impl Future with Self::Future also solves the problem:
error: implementation of `FnOnce` is not general enough
--> src/main.rs:10:5
|
10 | / async move {
11 | | let xs = unique_x.union(&cached).map(|x| x.len().to_string())
12 | | //.collect::<Vec<_>>()
13 | | ;
14 | | let blah = val.blah(xs.into_iter()).await;
15 | | }
| |_____^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'0 String) -> String` must implement `FnOnce<(&'1 String,)>`, for any two lifetimes `'0` and `'1`...
= note: ...but it actually implements `FnOnce<(&String,)>`
And because of how async works it can easily leak across the functions:
error: implementation of `FnOnce` is not general enough
--> src/main.rs:15:5
|
15 | foo(val, unique_x)
| ^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'0 String) -> String` must implement `FnOnce<(&'1 String,)>`, for any two lifetimes `'0` and `'1`...
= note: ...but it actually implements `FnOnce<(&String,)>`
In a function without a single lifetime argument. You may get some very confusing on the very top of your async stack because somewhere underneath there is one future that violates the Send constraint.
I'm not entirely sure if this is a diganostic error or a compiler issue, but i believe that the original code with impl Future should have been managed to infer that the resulting future is Send. the fact that this doesn't work:
110339 looks different, at least I couldn't fix it with extra async blocks, #110338 is a very big umbrella issue, so maybe some of issues listed in there relate to this.
Following code doesn't work on all the compilers I've checked, e.g. 1.80.0-nightly
This is surprising because a lot of alterations to this code fixes the issue, for example replacing
map(|x| *x)
withcopied()
, which is seemingly an equivalent replacement. Moreover, replacingimpl Future
withSelf::Future
also solves the problem:Also the error text is very cryptic:
And because of how
async
works it can easily leak across the functions:This function reports
In a function without a single lifetime argument. You may get some very confusing on the very top of your
async
stack because somewhere underneath there is one future that violates theSend
constraint.I'm not entirely sure if this is a diganostic error or a compiler issue, but i believe that the original code with
impl Future
should have been managed to infer that the resulting future isSend
. the fact that this doesn't work:But this does
Makes me think that this have to be a compiler issue