-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More unsoundness in future_sync
and future_desync
#8
Comments
Always having to box the future was a pain, so I wanted to eliminate that and also allow for this kind of code:
which is possible with |
I believe the fix to remove the need to use a boxed future is to add a trait like this: pub trait IntoBoxFuture<'a, 'b, TBorrow, TOutput> {
fn make_box(self, val: &'a mut TBorrow) -> BoxFuture<'b, TOutput>;
}
impl<'a, TFn, TBorrow, TFuture> IntoBoxFuture<'a, TBorrow, TFuture::Output> for TFn
where
TFn: FnOnce(&'a mut TBorrow) -> TFuture,
TFuture: 'a + Send + Future,
TBorrow: 'a,
{
fn make_box(self, val: &'a mut TBorrow) -> BoxFuture<'a, TFuture::Output> {
(self)(val).boxed()
}
} Then change the signature of pub fn future_sync<'a, TFn, TOutput>(&'a self, job: TFn) -> impl 'a + Future<Output=Result<TOutput, oneshot::Canceled>> + Send
where
TFn: 'a + Send + for<'b> IntoBoxFuture<'b, T, TOutput>,
TOutput: 'a + Send, and then make sure the function is called with a lifetime where the data is safe to borrow. I think this works perfectly for |
ecfaaad fixes this by going back to using The problem is that Rust isn't quite smart enough to infer it needs to create a |
There's no way to write this so that it works effortlessly with closures on the caller's end. There's only three options:
The last two options require helper traits to write the bounds. |
It's worth noting that syntax for explicitly higher-order closures is available on nightly behind the |
Ah, thanks for letting me know: I want to keep everything working with stable so this probably won't make it in until it's ready, but this definitely looks like something that will help with this problem (it's a fairly minor annoyance but always 'feels' wrong when it's a problem) |
From PR #7:
This was introduced by the change in v0.8 that removed the need to box the future, I think. The lifetime of the borrow is insufficiently restricted without the higher-order trait bound imposed on the function.
The text was updated successfully, but these errors were encountered: