From 974bdc80fe3214159dc30e0bbb76694900e613c0 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Sat, 1 Sep 2018 06:12:10 +0200 Subject: Update to a new pinning API. --- src/libcore/future/future.rs | 19 ++++++++++++------- src/libcore/future/future_obj.rs | 35 ++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 14 deletions(-) (limited to 'src/libcore/future') diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs index 520b6ebbbaa..6cf1925000e 100644 --- a/src/libcore/future/future.rs +++ b/src/libcore/future/future.rs @@ -12,8 +12,9 @@ reason = "futures in libcore are unstable", issue = "50547")] -use pin::PinMut; use marker::Unpin; +use ops; +use pin::Pin; use task::{self, Poll}; /// A future represents an asychronous computation. @@ -92,21 +93,25 @@ pub trait Future { /// [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending /// [`Poll::Ready(val)`]: ../task/enum.Poll.html#variant.Ready /// [`cx.waker()`]: ../task/struct.Context.html#method.waker - fn poll(self: PinMut, cx: &mut task::Context) -> Poll; + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll; } impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F { type Output = F::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { - F::poll(PinMut::new(&mut **self), cx) + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + F::poll(Pin::new(&mut **self), cx) } } -impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> { +impl Future for Pin

where + P: ops::DerefMut + Unpin, + F: Future + ?Sized, +{ type Output = F::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { - F::poll((*self).reborrow(), cx) + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + let pin: Pin<&mut F> = Pin::as_mut(&mut *self); + F::poll(pin, cx) } } diff --git a/src/libcore/future/future_obj.rs b/src/libcore/future/future_obj.rs index 68fe461aeae..b335cac6c1d 100644 --- a/src/libcore/future/future_obj.rs +++ b/src/libcore/future/future_obj.rs @@ -15,7 +15,8 @@ use fmt; use future::Future; use marker::{PhantomData, Unpin}; -use pin::PinMut; +use ops; +use pin::Pin; use task::{Context, Poll}; /// A custom trait object for polling futures, roughly akin to @@ -78,9 +79,9 @@ impl<'a, T> Future for LocalFutureObj<'a, T> { type Output = T; #[inline] - fn poll(self: PinMut, cx: &mut Context) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { unsafe { - (self.poll_fn)(self.ptr, cx) + ((*self).poll_fn)((*self).ptr, cx) } } } @@ -128,9 +129,11 @@ impl<'a, T> Future for FutureObj<'a, T> { type Output = T; #[inline] - fn poll(self: PinMut, cx: &mut Context) -> Poll { - let pinned_field = unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }; - pinned_field.poll(cx) + fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { + let pinned_field: Pin<&mut LocalFutureObj<'a, T>> = unsafe { + Pin::map_unchecked_mut(self, |x| &mut x.0) + }; + LocalFutureObj::poll(pinned_field, cx) } } @@ -175,7 +178,25 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F } unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll { - PinMut::new_unchecked(&mut *(ptr as *mut F)).poll(cx) + let p: Pin<&mut F> = Pin::new_unchecked(&mut *(ptr as *mut F)); + F::poll(p, cx) + } + + unsafe fn drop(_ptr: *mut ()) {} +} + +#[unstable(feature = "futures_api", issue = "50547")] +unsafe impl<'a, T, P, F> UnsafeFutureObj<'a, T> for Pin

where + P: ops::DerefMut + 'a, + F: Future + 'a, +{ + fn into_raw(mut self) -> *mut () { + unsafe { Pin::get_mut_unchecked(Pin::as_mut(&mut self)) as *mut F as *mut () } + } + + unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll { + let future: Pin<&mut F> = Pin::new_unchecked(&mut *(ptr as *mut F)); + F::poll(future, cx) } unsafe fn drop(_ptr: *mut ()) {} -- cgit 1.4.1-3-g733a5