diff --git a/Cargo.toml b/Cargo.toml index f02526a563..8b13b085ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,6 @@ members = [ "futures-util", "futures-test", ] + +[patch.crates-io] +pin-utils = { git = "https://github.com/Kroisse/pin-utils.git", branch = "pin" } diff --git a/futures-channel/benches/sync_mpsc.rs b/futures-channel/benches/sync_mpsc.rs index dc0b5c0411..f8fc4de5ca 100644 --- a/futures-channel/benches/sync_mpsc.rs +++ b/futures-channel/benches/sync_mpsc.rs @@ -1,14 +1,16 @@ #![feature(test, futures_api, pin, arbitrary_self_types)] +extern crate test; + use futures::ready; use futures::channel::mpsc::{self, Sender, UnboundedSender}; use futures::executor::LocalPool; use futures::stream::{Stream, StreamExt}; use futures::sink::Sink; use futures::task::{self, Poll, Wake, LocalWaker}; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::Arc; -use test::Bencher; +use self::test::Bencher; fn notify_noop() -> LocalWaker { struct Noop; @@ -100,16 +102,16 @@ struct TestSender { impl Stream for TestSender { type Item = u32; - fn poll_next(mut self: PinMut, cx: &mut task::Context) + fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { let this = &mut *self; - let mut tx = PinMut::new(&mut this.tx); + let mut tx = Pin::new(&mut this.tx); - ready!(tx.reborrow().poll_ready(cx)).unwrap(); - tx.reborrow().start_send(this.last + 1).unwrap(); + ready!(tx.as_mut().poll_ready(cx)).unwrap(); + tx.as_mut().start_send(this.last + 1).unwrap(); this.last += 1; - assert_eq!(Poll::Ready(Ok(())), tx.reborrow().poll_flush(cx)); + assert_eq!(Poll::Ready(Ok(())), tx.as_mut().poll_flush(cx)); Poll::Ready(Some(this.last)) } } diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index 675aca7eb1..fa98b7f951 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -84,7 +84,7 @@ use std::any::Any; use std::error::Error; use std::fmt; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; @@ -113,7 +113,7 @@ pub struct Sender { maybe_parked: bool, } -// We never project PinMut to `PinMut` +// We never project Pin<&mut Sender> to `Pin<&mut T>` impl Unpin for Sender {} /// The transmission end of an unbounded mpsc channel. @@ -139,7 +139,7 @@ pub struct Receiver { #[derive(Debug)] pub struct UnboundedReceiver(Receiver); -// `PinMut>` is never projected to `PinMut` +// `Pin<&mut UnboundedReceiver>` is never projected to `Pin<&mut T>` impl Unpin for UnboundedReceiver {} /// The error type for [`Sender`s](Sender) used as `Sink`s. @@ -953,14 +953,14 @@ impl Receiver { } } -// The receiver does not ever take a PinMut to the inner T +// The receiver does not ever take a Pin to the inner T impl Unpin for Receiver {} impl Stream for Receiver { type Item = T; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { loop { @@ -1030,10 +1030,10 @@ impl Stream for UnboundedReceiver { type Item = T; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - PinMut::new(&mut self.0).poll_next(cx) + Pin::new(&mut self.0).poll_next(cx) } } diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index 7e261e621c..452e4b5735 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -3,7 +3,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll, Waker}; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; @@ -29,7 +29,7 @@ pub struct Sender { inner: Arc>, } -// The channels do not ever project PinMut to the inner T +// The channels do not ever project Pin to the inner T impl Unpin for Receiver {} impl Unpin for Sender {} @@ -419,7 +419,7 @@ impl Future for Receiver { type Output = Result; fn poll( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.inner.recv(cx) diff --git a/futures-channel/tests/mpsc.rs b/futures-channel/tests/mpsc.rs index 5356a70bd4..84a9cb00d1 100644 --- a/futures-channel/tests/mpsc.rs +++ b/futures-channel/tests/mpsc.rs @@ -32,30 +32,30 @@ fn send_recv_no_buffer() { let (tx, rx) = mpsc::channel::(0); pin_mut!(tx, rx); - assert!(tx.reborrow().poll_flush(cx).is_ready()); - assert!(tx.reborrow().poll_ready(cx).is_ready()); + assert!(tx.as_mut().poll_flush(cx).is_ready()); + assert!(tx.as_mut().poll_ready(cx).is_ready()); // Send first message - assert!(tx.reborrow().start_send(1).is_ok()); - assert!(tx.reborrow().poll_ready(cx).is_pending()); + assert!(tx.as_mut().start_send(1).is_ok()); + assert!(tx.as_mut().poll_ready(cx).is_pending()); // poll_ready said Pending, so no room in buffer, therefore new sends // should get rejected with is_full. - assert!(tx.reborrow().start_send(0).unwrap_err().is_full()); - assert!(tx.reborrow().poll_ready(cx).is_pending()); + assert!(tx.as_mut().start_send(0).unwrap_err().is_full()); + assert!(tx.as_mut().poll_ready(cx).is_pending()); // Take the value - assert_eq!(rx.reborrow().poll_next(cx), Poll::Ready(Some(1))); - assert!(tx.reborrow().poll_ready(cx).is_ready()); + assert_eq!(rx.as_mut().poll_next(cx), Poll::Ready(Some(1))); + assert!(tx.as_mut().poll_ready(cx).is_ready()); // Send second message - assert!(tx.reborrow().poll_ready(cx).is_ready()); - assert!(tx.reborrow().start_send(2).is_ok()); - assert!(tx.reborrow().poll_ready(cx).is_pending()); + assert!(tx.as_mut().poll_ready(cx).is_ready()); + assert!(tx.as_mut().start_send(2).is_ok()); + assert!(tx.as_mut().poll_ready(cx).is_pending()); // Take the value - assert_eq!(rx.reborrow().poll_next(cx), Poll::Ready(Some(2))); - assert!(tx.reborrow().poll_ready(cx).is_ready()); + assert_eq!(rx.as_mut().poll_next(cx), Poll::Ready(Some(2))); + assert!(tx.as_mut().poll_ready(cx).is_ready()); Poll::Ready(()) })); diff --git a/futures-channel/tests/oneshot.rs b/futures-channel/tests/oneshot.rs index 2b7bcff91b..acf83a9614 100644 --- a/futures-channel/tests/oneshot.rs +++ b/futures-channel/tests/oneshot.rs @@ -4,7 +4,7 @@ use futures::channel::oneshot::{self, Sender}; use futures::executor::block_on; use futures::future::{Future, FutureExt, poll_fn}; use futures::task::{self, Poll}; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::mpsc; use std::thread; @@ -42,7 +42,7 @@ struct WaitForCancel { impl Future for WaitForCancel { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.tx.poll_cancel(cx) } } diff --git a/futures-core/src/future.rs b/futures-core/src/future.rs index fc5a71165a..fbbf9673b4 100644 --- a/futures-core/src/future.rs +++ b/futures-core/src/future.rs @@ -1,7 +1,7 @@ //! Futures. use crate::task::{self, Poll}; -use core::pin::PinMut; +use core::pin::Pin; pub use core::future::{Future, FutureObj, LocalFutureObj, UnsafeFutureObj}; @@ -20,7 +20,7 @@ pub trait TryFuture { /// directly inheriting from the `Future` trait; in the future it won't be /// needed. fn try_poll( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll>; } @@ -32,7 +32,7 @@ impl TryFuture for F type Error = E; #[inline] - fn try_poll(self: PinMut, cx: &mut task::Context) -> Poll { + fn try_poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.poll(cx) } } diff --git a/futures-core/src/stream/mod.rs b/futures-core/src/stream/mod.rs index 3d4a6d1438..867334c320 100644 --- a/futures-core/src/stream/mod.rs +++ b/futures-core/src/stream/mod.rs @@ -2,7 +2,7 @@ use crate::task::{self, Poll}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; #[cfg(feature = "either")] use either::Either; @@ -52,7 +52,7 @@ pub trait Stream { /// to ensure that `poll_next` always returns `Ready(None)` in subsequent /// calls. fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll>; } @@ -61,21 +61,21 @@ impl<'a, S: ?Sized + Stream + Unpin> Stream for &'a mut S { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - S::poll_next(PinMut::new(&mut **self), cx) + S::poll_next(Pin::new(&mut **self), cx) } } -impl<'a, S: ?Sized + Stream> Stream for PinMut<'a, S> { +impl<'a, S: ?Sized + Stream> Stream for Pin<&'a mut S> { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - S::poll_next((*self).reborrow(), cx) + S::poll_next((*self).as_mut(), cx) } } @@ -86,11 +86,11 @@ impl Stream for Either { type Item = A::Item; - fn poll_next(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { unsafe { - match PinMut::get_mut_unchecked(self) { - Either::Left(a) => PinMut::new_unchecked(a).poll_next(cx), - Either::Right(b) => PinMut::new_unchecked(b).poll_next(cx), + match Pin::get_mut_unchecked(self) { + Either::Left(a) => Pin::new_unchecked(a).poll_next(cx), + Either::Right(b) => Pin::new_unchecked(b).poll_next(cx), } } } @@ -110,7 +110,7 @@ pub trait TryStream { /// This method is a stopgap for a compiler limitation that prevents us from /// directly inheriting from the `Stream` trait; in the future it won't be /// needed. - fn try_poll_next(self: PinMut, cx: &mut task::Context) + fn try_poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll>>; } @@ -120,7 +120,7 @@ impl TryStream for S type Ok = T; type Error = E; - fn try_poll_next(self: PinMut, cx: &mut task::Context) + fn try_poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll>> { self.poll_next(cx) @@ -129,27 +129,26 @@ impl TryStream for S if_std! { use std::boxed::Box; - use std::pin::PinBox; impl Stream for Box { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - PinMut::new(&mut **self).poll_next(cx) + Pin::new(&mut **self).poll_next(cx) } } - impl Stream for PinBox { + impl Stream for Pin> { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - self.as_pin_mut().poll_next(cx) + S::poll_next((*self).as_mut(), cx) } } @@ -157,10 +156,10 @@ if_std! { type Item = S::Item; fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }.poll_next(cx) + unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }.poll_next(cx) } } @@ -168,7 +167,7 @@ if_std! { type Item = T; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, _cx: &mut task::Context, ) -> Poll> { Poll::Ready(self.pop_front()) diff --git a/futures-core/src/stream/stream_obj.rs b/futures-core/src/stream/stream_obj.rs index 9063f953d9..d821a72aa2 100644 --- a/futures-core/src/stream/stream_obj.rs +++ b/futures-core/src/stream/stream_obj.rs @@ -2,7 +2,7 @@ use super::Stream; use crate::task::{self, Poll}; use core::fmt; use core::marker::{PhantomData, Unpin}; -use core::pin::PinMut; +use core::pin::Pin; /// A custom trait object for polling streams, roughly akin to /// `Box + 'a>`. @@ -64,7 +64,7 @@ impl<'a, T> Stream for LocalStreamObj<'a, T> { #[inline] fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { unsafe { (self.poll_next_fn)(self.ptr, cx) } @@ -112,10 +112,10 @@ impl<'a, T> Stream for StreamObj<'a, T> { #[inline] fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - let pinned_field = unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }; + let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }; pinned_field.poll_next(cx) } } @@ -168,25 +168,25 @@ where ptr: *mut (), cx: &mut task::Context, ) -> Poll> { - PinMut::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) + Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) } unsafe fn drop(_ptr: *mut ()) {} } -unsafe impl<'a, T, F> UnsafeStreamObj<'a, T> for PinMut<'a, F> +unsafe impl<'a, T, F> UnsafeStreamObj<'a, T> for Pin<&'a mut F> where F: Stream + 'a, { fn into_raw(self) -> *mut () { - unsafe { PinMut::get_mut_unchecked(self) as *mut F as *mut () } + unsafe { Pin::get_mut_unchecked(self) as *mut F as *mut () } } unsafe fn poll_next( ptr: *mut (), cx: &mut task::Context, ) -> Poll> { - PinMut::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) + Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) } unsafe fn drop(_ptr: *mut ()) {} @@ -194,7 +194,6 @@ where if_std! { use std::boxed::Box; - use std::pin::PinBox; unsafe impl<'a, T, F> UnsafeStreamObj<'a, T> for Box where F: Stream + 'a @@ -205,7 +204,7 @@ if_std! { unsafe fn poll_next(ptr: *mut (), cx: &mut task::Context) -> Poll> { let ptr = ptr as *mut F; - let pin: PinMut = PinMut::new_unchecked(&mut *ptr); + let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); pin.poll_next(cx) } @@ -214,26 +213,26 @@ if_std! { } } - unsafe impl<'a, T, F> UnsafeStreamObj<'a, T> for PinBox + unsafe impl<'a, T, F> UnsafeStreamObj<'a, T> for Pin> where F: Stream + 'a { - fn into_raw(self) -> *mut () { - PinBox::into_raw(self) as *mut () + fn into_raw(mut self) -> *mut () { + unsafe { Pin::get_mut_unchecked(Pin::as_mut(&mut self)) as *mut F as *mut () } } unsafe fn poll_next(ptr: *mut (), cx: &mut task::Context) -> Poll> { let ptr = ptr as *mut F; - let pin: PinMut = PinMut::new_unchecked(&mut *ptr); + let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); pin.poll_next(cx) } unsafe fn drop(ptr: *mut ()) { - drop(PinBox::from_raw(ptr as *mut F)) + drop(Box::from_raw(ptr as *mut F)) } } - impl<'a, F: Stream + Send + 'a> From> for StreamObj<'a, ()> { - fn from(boxed: PinBox) -> Self { + impl<'a, F: Stream + Send + 'a> From>> for StreamObj<'a, ()> { + fn from(boxed: Pin>) -> Self { StreamObj::new(boxed) } } @@ -244,8 +243,8 @@ if_std! { } } - impl<'a, F: Stream + 'a> From> for LocalStreamObj<'a, ()> { - fn from(boxed: PinBox) -> Self { + impl<'a, F: Stream + 'a> From>> for LocalStreamObj<'a, ()> { + fn from(boxed: Pin>) -> Self { LocalStreamObj::new(boxed) } } diff --git a/futures-executor/benches/poll.rs b/futures-executor/benches/poll.rs index e46ff524df..84a653497e 100644 --- a/futures-executor/benches/poll.rs +++ b/futures-executor/benches/poll.rs @@ -1,12 +1,14 @@ #![feature(test, pin, arbitrary_self_types, futures_api)] +extern crate test; + use futures::executor::LocalPool; use futures::future::{Future, FutureExt}; use futures::task::{self, Poll, Waker, LocalWaker, Wake}; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::Arc; -use test::Bencher; +use self::test::Bencher; fn notify_noop() -> LocalWaker { struct Noop; @@ -31,7 +33,7 @@ fn task_init(b: &mut Bencher) { impl Future for MyFuture { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { if self.num == NUM { Poll::Ready(()) } else { diff --git a/futures-executor/benches/thread_notify.rs b/futures-executor/benches/thread_notify.rs index a4e09a4b73..6aa4c06d55 100644 --- a/futures-executor/benches/thread_notify.rs +++ b/futures-executor/benches/thread_notify.rs @@ -1,11 +1,13 @@ #![feature(test, futures_api, pin, arbitrary_self_types)] +extern crate test; + use futures::executor::block_on; use futures::future::Future; use futures::task::{self, Poll, Waker}; use std::marker::Unpin; -use std::pin::PinMut; -use test::Bencher; +use std::pin::Pin; +use self::test::Bencher; #[bench] fn thread_yield_single_thread_one_wait(b: &mut Bencher) { @@ -18,7 +20,7 @@ fn thread_yield_single_thread_one_wait(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { @@ -46,7 +48,7 @@ fn thread_yield_single_thread_many_wait(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { @@ -83,7 +85,7 @@ fn thread_yield_multi_thread(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index b3e95ccddf..ded02fbc61 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -154,7 +154,7 @@ impl LocalPool { let mut main_cx = Context::new(local_waker, spawn); // if our main task is done, so are we - let result = future.reborrow().poll(&mut main_cx); + let result = future.as_mut().poll(&mut main_cx); if let Poll::Ready(output) = result { return Poll::Ready(output); } diff --git a/futures-executor/tests/local_pool.rs b/futures-executor/tests/local_pool.rs index a4fcee6921..65d6f49efc 100644 --- a/futures-executor/tests/local_pool.rs +++ b/futures-executor/tests/local_pool.rs @@ -5,7 +5,7 @@ use futures::executor::LocalPool; use futures::future::{Future, lazy}; use futures::task::{self, Poll, Spawn}; use std::cell::{Cell, RefCell}; -use std::pin::{PinBox, PinMut}; +use std::pin::Pin; use std::rc::Rc; struct Pending(Rc<()>); @@ -13,7 +13,7 @@ struct Pending(Rc<()>); impl Future for Pending { type Output = (); - fn poll(self: PinMut, _cx: &mut task::Context) -> Poll<()> { + fn poll(self: Pin<&mut Self>, _cx: &mut task::Context) -> Poll<()> { Poll::Pending } } @@ -43,7 +43,7 @@ fn run_until_single_future() { fn run_until_ignores_spawned() { let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); - spawn.spawn_local_obj(PinBox::new(pending()).into()).unwrap(); + spawn.spawn_local_obj(Box::pinned(pending()).into()).unwrap(); assert_eq!(pool.run_until(lazy(|_| ()), &mut spawn), ()); } @@ -52,7 +52,19 @@ fn run_until_executes_spawned() { let (tx, rx) = oneshot::channel(); let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); - spawn.spawn_local_obj(PinBox::new(lazy(move |_| { + spawn.spawn_local_obj(Box::new(lazy(move |_| { + tx.send(()).unwrap(); + () + })).into()).unwrap(); + pool.run_until(rx, &mut spawn).unwrap(); +} + +#[test] +fn run_until_executes_spawned_pinned() { + let (tx, rx) = oneshot::channel(); + let mut pool = LocalPool::new(); + let mut spawn = pool.spawner(); + spawn.spawn_local_obj(Box::pinned(lazy(move |_| { tx.send(()).unwrap(); () })).into()).unwrap(); @@ -68,8 +80,8 @@ fn run_executes_spawned() { let mut spawn = pool.spawner(); let mut spawn2 = pool.spawner(); - spawn.spawn_local_obj(PinBox::new(lazy(move |_| { - spawn2.spawn_local_obj(PinBox::new(lazy(move |_| { + spawn.spawn_local_obj(Box::pinned(lazy(move |_| { + spawn2.spawn_local_obj(Box::pinned(lazy(move |_| { cnt2.set(cnt2.get() + 1); () })).into()).unwrap(); @@ -93,7 +105,29 @@ fn run_spawn_many() { for _ in 0..ITER { let cnt = cnt.clone(); - spawn.spawn_local_obj(PinBox::new(lazy(move |_| { + spawn.spawn_local_obj(Box::new(lazy(move |_| { + cnt.set(cnt.get() + 1); + () + })).into()).unwrap(); + } + + pool.run(&mut spawn); + + assert_eq!(cnt.get(), ITER); +} + +#[test] +fn run_spawn_many_pinned() { + const ITER: usize = 200; + + let cnt = Rc::new(Cell::new(0)); + + let mut pool = LocalPool::new(); + let mut spawn = pool.spawner(); + + for _ in 0..ITER { + let cnt = cnt.clone(); + spawn.spawn_local_obj(Box::pinned(lazy(move |_| { cnt.set(cnt.get() + 1); () })).into()).unwrap(); @@ -110,7 +144,7 @@ fn nesting_run() { let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); - spawn.spawn_obj(PinBox::new(lazy(|_| { + spawn.spawn_obj(Box::pinned(lazy(|_| { let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); pool.run(&mut spawn); @@ -130,7 +164,7 @@ fn tasks_are_scheduled_fairly() { impl Future for Spin { type Output = (); - fn poll(self: PinMut, cx: &mut task::Context) -> Poll<()> { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { let mut state = self.state.borrow_mut(); if self.idx == 0 { @@ -157,16 +191,21 @@ fn tasks_are_scheduled_fairly() { let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); - spawn.spawn_local_obj(PinBox::new(Spin { + spawn.spawn_local_obj(Box::pinned(Spin { state: state.clone(), idx: 0, }).into()).unwrap(); - spawn.spawn_local_obj(PinBox::new(Spin { - state: state, + spawn.spawn_local_obj(Box::pinned(Spin { + state: state.clone(), idx: 1, }).into()).unwrap(); pool.run(&mut spawn); -} + { + let state = state.borrow(); + assert_eq!(state[0], 50); + assert_eq!(state[1], 100); + } +} diff --git a/futures-sink/src/channel_impls.rs b/futures-sink/src/channel_impls.rs index d0138f335e..ad977631d8 100644 --- a/futures-sink/src/channel_impls.rs +++ b/futures-sink/src/channel_impls.rs @@ -1,25 +1,25 @@ use crate::{Sink, Poll}; use futures_core::task; use futures_channel::mpsc::{Sender, SendError, UnboundedSender}; -use std::pin::PinMut; +use std::pin::Pin; impl Sink for Sender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { (*self).poll_ready(cx) } - fn start_send(mut self: PinMut, msg: T) -> Result<(), Self::SinkError> { + fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { (*self).start_send(msg) } - fn poll_flush(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(mut self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } @@ -29,19 +29,19 @@ impl Sink for UnboundedSender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { UnboundedSender::poll_ready(&*self, cx) } - fn start_send(mut self: PinMut, msg: T) -> Result<(), Self::SinkError> { + fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { UnboundedSender::start_send(&mut *self, msg) } - fn poll_flush(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } @@ -51,20 +51,20 @@ impl<'a, T> Sink for &'a UnboundedSender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { UnboundedSender::poll_ready(*self, cx) } - fn start_send(self: PinMut, msg: T) -> Result<(), Self::SinkError> { + fn start_send(self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { self.unbounded_send(msg) .map_err(|err| err.into_send_error()) } - fn poll_flush(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } diff --git a/futures-sink/src/lib.rs b/futures-sink/src/lib.rs index 6141d36a00..65e9cee4e3 100644 --- a/futures-sink/src/lib.rs +++ b/futures-sink/src/lib.rs @@ -18,7 +18,7 @@ macro_rules! if_std { use futures_core::task::{self, Poll}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; /// A `Sink` is a value into which other values can be sent, asynchronously. /// @@ -65,7 +65,7 @@ pub trait Sink { /// /// In most cases, if the sink encounters an error, the sink will /// permanently be unable to receive items. - fn poll_ready(self: PinMut, cx: &mut task::Context) -> Poll>; + fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; /// Begin the process of sending a value to the sink. /// Each call to this function must be proceeded by a successful call to @@ -86,7 +86,7 @@ pub trait Sink { /// /// In most cases, if the sink encounters an error, the sink will /// permanently be unable to receive items. - fn start_send(self: PinMut, item: Self::SinkItem) + fn start_send(self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError>; /// Flush any remaining output from this sink. @@ -101,7 +101,7 @@ pub trait Sink { /// /// In most cases, if the sink encounters an error, the sink will /// permanently be unable to receive items. - fn poll_flush(self: PinMut, cx: &mut task::Context) -> Poll>; + fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; /// Flush any remaining output and close this sink, if necessary. /// @@ -114,48 +114,48 @@ pub trait Sink { /// /// If this function encounters an error, the sink should be considered to /// have failed permanently, and no more `Sink` methods should be called. - fn poll_close(self: PinMut, cx: &mut task::Context) -> Poll>; + fn poll_close(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; } impl<'a, S: ?Sized + Sink + Unpin> Sink for &'a mut S { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_ready(cx) + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_ready(cx) } - fn start_send(mut self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { - PinMut::new(&mut **self).start_send(item) + fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { + Pin::new(&mut **self).start_send(item) } - fn poll_flush(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_flush(cx) + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_flush(cx) } - fn poll_close(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_close(cx) + fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_close(cx) } } -impl<'a, S: ?Sized + Sink> Sink for PinMut<'a, S> { +impl<'a, S: ?Sized + Sink> Sink for Pin<&'a mut S> { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: PinMut, cx: &mut task::Context) -> Poll> { - S::poll_ready((*self).reborrow(), cx) + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + S::poll_ready((*self).as_mut(), cx) } - fn start_send(mut self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { - S::start_send((*self).reborrow(), item) + fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { + S::start_send((*self).as_mut(), item) } - fn poll_flush(mut self: PinMut, cx: &mut task::Context) -> Poll> { - S::poll_flush((*self).reborrow(), cx) + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + S::poll_flush((*self).as_mut(), cx) } - fn poll_close(mut self: PinMut, cx: &mut task::Context) -> Poll> { - S::poll_close((*self).reborrow(), cx) + fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + S::poll_close((*self).as_mut(), cx) } } @@ -171,21 +171,21 @@ if_std! { type SinkItem = T; type SinkError = VecSinkError; - fn poll_ready(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn start_send(self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { + fn start_send(self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { // TODO: impl Unpin for Vec {} - unsafe { PinMut::get_mut_unchecked(self) }.push(item); + unsafe { Pin::get_mut_unchecked(self) }.push(item); Ok(()) } - fn poll_flush(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } } @@ -194,21 +194,21 @@ if_std! { type SinkItem = T; type SinkError = VecSinkError; - fn poll_ready(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn start_send(self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { + fn start_send(self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { // TODO: impl Unpin for Vec {} - unsafe { PinMut::get_mut_unchecked(self) }.push_back(item); + unsafe { Pin::get_mut_unchecked(self) }.push_back(item); Ok(()) } - fn poll_flush(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Ok(())) } } @@ -217,20 +217,20 @@ if_std! { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_ready(cx) + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_ready(cx) } - fn start_send(mut self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { - PinMut::new(&mut **self).start_send(item) + fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { + Pin::new(&mut **self).start_send(item) } - fn poll_flush(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_flush(cx) + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_flush(cx) } - fn poll_close(mut self: PinMut, cx: &mut task::Context) -> Poll> { - PinMut::new(&mut **self).poll_close(cx) + fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + Pin::new(&mut **self).poll_close(cx) } } } @@ -246,38 +246,38 @@ impl Sink for Either type SinkItem = ::SinkItem; type SinkError = ::SinkError; - fn poll_ready(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { unsafe { - match PinMut::get_mut_unchecked(self) { - Either::Left(x) => PinMut::new_unchecked(x).poll_ready(cx), - Either::Right(x) => PinMut::new_unchecked(x).poll_ready(cx), + match Pin::get_mut_unchecked(self) { + Either::Left(x) => Pin::new_unchecked(x).poll_ready(cx), + Either::Right(x) => Pin::new_unchecked(x).poll_ready(cx), } } } - fn start_send(self: PinMut, item: Self::SinkItem) -> Result<(), Self::SinkError> { + fn start_send(self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { unsafe { - match PinMut::get_mut_unchecked(self) { - Either::Left(x) => PinMut::new_unchecked(x).start_send(item), - Either::Right(x) => PinMut::new_unchecked(x).start_send(item), + match Pin::get_mut_unchecked(self) { + Either::Left(x) => Pin::new_unchecked(x).start_send(item), + Either::Right(x) => Pin::new_unchecked(x).start_send(item), } } } - fn poll_flush(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { unsafe { - match PinMut::get_mut_unchecked(self) { - Either::Left(x) => PinMut::new_unchecked(x).poll_flush(cx), - Either::Right(x) => PinMut::new_unchecked(x).poll_flush(cx), + match Pin::get_mut_unchecked(self) { + Either::Left(x) => Pin::new_unchecked(x).poll_flush(cx), + Either::Right(x) => Pin::new_unchecked(x).poll_flush(cx), } } } - fn poll_close(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { unsafe { - match PinMut::get_mut_unchecked(self) { - Either::Left(x) => PinMut::new_unchecked(x).poll_close(cx), - Either::Right(x) => PinMut::new_unchecked(x).poll_close(cx), + match Pin::get_mut_unchecked(self) { + Either::Left(x) => Pin::new_unchecked(x).poll_close(cx), + Either::Right(x) => Pin::new_unchecked(x).poll_close(cx), } } } diff --git a/futures-test/src/assert.rs b/futures-test/src/assert.rs index 93e4b0b4a1..b92ffab12a 100644 --- a/futures-test/src/assert.rs +++ b/futures-test/src/assert.rs @@ -30,7 +30,7 @@ macro_rules! assert_stream_pending { ($stream:expr) => {{ let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); - let stream = $crate::std_reexport::pin::PinMut::new(stream); + let stream = $crate::std_reexport::pin::Pin::new(stream); let cx = &mut $crate::task::no_spawn_context(); let poll = $crate::futures_core_reexport::stream::Stream::poll_next( stream, cx, @@ -67,7 +67,7 @@ macro_rules! assert_stream_next { ($stream:expr, $item:expr) => {{ let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); - let stream = $crate::std_reexport::pin::PinMut::new(stream); + let stream = $crate::std_reexport::pin::Pin::new(stream); let cx = &mut $crate::task::no_spawn_context(); match $crate::futures_core_reexport::stream::Stream::poll_next(stream, cx) { $crate::futures_core_reexport::task::Poll::Ready(Some(x)) => { @@ -110,7 +110,7 @@ macro_rules! assert_stream_done { ($stream:expr) => {{ let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); - let stream = $crate::std_reexport::pin::PinMut::new(stream); + let stream = $crate::std_reexport::pin::Pin::new(stream); let cx = &mut $crate::task::no_spawn_context(); match $crate::futures_core_reexport::stream::Stream::poll_next(stream, cx) { $crate::futures_core_reexport::task::Poll::Ready(Some(_)) => { diff --git a/futures-test/src/future/assert_unmoved.rs b/futures-test/src/future/assert_unmoved.rs index 225fbf78f6..0d117288bc 100644 --- a/futures-test/src/future/assert_unmoved.rs +++ b/futures-test/src/future/assert_unmoved.rs @@ -2,7 +2,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Pinned; -use std::pin::PinMut; +use std::pin::Pin; use std::ptr; /// Combinator for the @@ -33,7 +33,7 @@ impl Future for AssertUnmoved { type Output = Fut::Output; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { let cur_this = &*self as *const Self; diff --git a/futures-test/src/future/pending_once.rs b/futures-test/src/future/pending_once.rs index d98e53242f..b8f0c3684c 100644 --- a/futures-test/src/future/pending_once.rs +++ b/futures-test/src/future/pending_once.rs @@ -1,6 +1,6 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; -use std::pin::PinMut; +use std::pin::Pin; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Combinator that guarantees one [`Poll::Pending`] before polling its inner @@ -32,7 +32,7 @@ impl Future for PendingOnce { type Output = Fut::Output; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { if *self.polled_before() { diff --git a/futures-util/benches/futures_unordered.rs b/futures-util/benches/futures_unordered.rs index 759021741a..2075233c48 100644 --- a/futures-util/benches/futures_unordered.rs +++ b/futures-util/benches/futures_unordered.rs @@ -1,5 +1,7 @@ #![feature(test, futures_api)] +extern crate test; + use futures::channel::oneshot; use futures::executor::block_on; use futures::future; @@ -7,7 +9,7 @@ use futures::stream::{StreamExt, FuturesUnordered}; use futures::task::Poll; use std::collections::VecDeque; use std::thread; -use test::Bencher; +use self::test::Bencher; #[bench] fn oneshots(b: &mut Bencher) { diff --git a/futures-util/src/async_await/join.rs b/futures-util/src/async_await/join.rs index c3619c889d..bb597d6461 100644 --- a/futures-util/src/async_await/join.rs +++ b/futures-util/src/async_await/join.rs @@ -33,14 +33,14 @@ macro_rules! join { let mut all_done = true; $( if $crate::core_reexport::future::Future::poll( - unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }, cx).is_pending() + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, cx).is_pending() { all_done = false; } )* if all_done { $crate::core_reexport::task::Poll::Ready(($( - unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }.take_output().unwrap(), + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }.take_output().unwrap(), )*)) } else { $crate::core_reexport::task::Poll::Pending @@ -101,15 +101,15 @@ macro_rules! try_join { let mut all_done = true; $( if $crate::core_reexport::future::Future::poll( - unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }, cx).is_pending() + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, cx).is_pending() { all_done = false; - } else if unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }.output_mut().unwrap().is_err() { + } else if unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }.output_mut().unwrap().is_err() { // `.err().unwrap()` rather than `.unwrap_err()` so that we don't introduce // a `T: Debug` bound. return $crate::core_reexport::task::Poll::Ready( $crate::core_reexport::result::Result::Err( - unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }.take_output().unwrap().err().unwrap() + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }.take_output().unwrap().err().unwrap() ) ); } @@ -119,7 +119,7 @@ macro_rules! try_join { $crate::core_reexport::result::Result::Ok(($( // `.ok().unwrap()` rather than `.unwrap()` so that we don't introduce // an `E: Debug` bound. - unsafe { $crate::core_reexport::pin::PinMut::new_unchecked(&mut $fut) }.take_output().unwrap().ok().unwrap(), + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }.take_output().unwrap().ok().unwrap(), )*)) ) } else { diff --git a/futures-util/src/async_await/pending.rs b/futures-util/src/async_await/pending.rs index 75bec84617..302e7b3213 100644 --- a/futures-util/src/async_await/pending.rs +++ b/futures-util/src/async_await/pending.rs @@ -1,12 +1,12 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; /// A macro which yields to the event loop once. -/// -/// This is equivalent to returning [`Poll::Pending`](futures_core::task::Poll) -/// from a [`Future::poll`](futures_core::future::Future::poll) implementation. -/// Similarly, when using this macro, it must be ensured that [`wake`](std::task::Waker::wake) +/// +/// This is equivalent to returning [`Poll::Pending`](futures_core::task::Poll) +/// from a [`Future::poll`](futures_core::future::Future::poll) implementation. +/// Similarly, when using this macro, it must be ensured that [`wake`](std::task::Waker::wake) /// is called somewhere when further progress can be made. /// /// This macro is only usable inside of async functions, closures, and blocks. @@ -30,7 +30,7 @@ pub struct PendingOnce { impl Future for PendingOnce { type Output = (); - fn poll(mut self: PinMut, _: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll { if self.is_ready { Poll::Ready(()) } else { diff --git a/futures-util/src/async_await/poll.rs b/futures-util/src/async_await/poll.rs index 3c12ca0081..43b0ee16ae 100644 --- a/futures-util/src/async_await/poll.rs +++ b/futures-util/src/async_await/poll.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -27,7 +27,7 @@ pub struct PollOnce { impl Future for PollOnce { type Output = Poll; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { - Poll::Ready(PinMut::new(&mut self.future).poll(cx)) + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + Poll::Ready(Pin::new(&mut self.future).poll(cx)) } } diff --git a/futures-util/src/async_await/select.rs b/futures-util/src/async_await/select.rs index 40887da6b9..136cfcb3a2 100644 --- a/futures-util/src/async_await/select.rs +++ b/futures-util/src/async_await/select.rs @@ -50,7 +50,7 @@ macro_rules! select { let __priv_res = await!($crate::future::poll_fn(|cx| { $( match $crate::core_reexport::future::Future::poll( - $crate::core_reexport::pin::PinMut::new(&mut $name), cx) + $crate::core_reexport::pin::Pin::new(&mut $name), cx) { $crate::core_reexport::task::Poll::Ready(x) => return $crate::core_reexport::task::Poll::Ready(__PrivResult::$name(x)), diff --git a/futures-util/src/compat/compat01to03.rs b/futures-util/src/compat/compat01to03.rs index 7cf34e1b80..61b10f1334 100644 --- a/futures-util/src/compat/compat01to03.rs +++ b/futures-util/src/compat/compat01to03.rs @@ -5,19 +5,19 @@ use futures::executor::{ }; use futures::{Async as Async01, Future as Future01, Stream as Stream01}; use futures_core::{task as task03, Future as Future03, Stream as Stream03}; -use std::pin::PinMut; +use std::pin::Pin; impl Future03 for Compat { type Output = Result; fn poll( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task03::Context, ) -> task03::Poll { let notify = &WakerToHandle(cx.waker()); executor01::with_notify(notify, 0, move || { - match unsafe { PinMut::get_mut_unchecked(self) }.inner.poll() { + match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { Ok(Async01::Ready(t)) => task03::Poll::Ready(Ok(t)), Ok(Async01::NotReady) => task03::Poll::Pending, Err(e) => task03::Poll::Ready(Err(e)), @@ -30,13 +30,13 @@ impl Stream03 for Compat { type Item = Result; fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task03::Context, ) -> task03::Poll> { let notify = &WakerToHandle(cx.waker()); executor01::with_notify(notify, 0, move || { - match unsafe { PinMut::get_mut_unchecked(self) }.inner.poll() { + match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { Ok(Async01::Ready(Some(t))) => task03::Poll::Ready(Some(Ok(t))), Ok(Async01::Ready(None)) => task03::Poll::Ready(None), Ok(Async01::NotReady) => task03::Poll::Pending, diff --git a/futures-util/src/compat/compat03to01.rs b/futures-util/src/compat/compat03to01.rs index 951da79423..4a190df312 100644 --- a/futures-util/src/compat/compat03to01.rs +++ b/futures-util/src/compat/compat03to01.rs @@ -8,7 +8,7 @@ use futures_core::{ task as task03, TryFuture as TryFuture03, TryStream as TryStream03, }; use futures_sink::Sink as Sink03; -use std::{marker::Unpin, pin::PinMut, sync::Arc}; +use std::{marker::Unpin, pin::Pin, sync::Arc}; impl Future01 for Compat where @@ -58,7 +58,7 @@ where item: Self::SinkItem, ) -> StartSend01 { with_context(self, |mut inner, cx| { - match inner.reborrow().poll_ready(cx) { + match inner.as_mut().poll_ready(cx) { task03::Poll::Ready(Ok(())) => { inner.start_send(item).map(|()| AsyncSink01::Ready) } @@ -102,10 +102,10 @@ fn with_context(compat: &mut Compat, f: F) -> R where T: Unpin, E: task03::Spawn, - F: FnOnce(PinMut, &mut task03::Context) -> R, + F: FnOnce(Pin<&mut T>, &mut task03::Context) -> R, { let waker = current_as_waker(); let spawn = compat.spawn.as_mut().unwrap(); let mut cx = task03::Context::new(&waker, spawn); - f(PinMut::new(&mut compat.inner), &mut cx) + f(Pin::new(&mut compat.inner), &mut cx) } diff --git a/futures-util/src/future/abortable.rs b/futures-util/src/future/abortable.rs index 35ba071d79..645e4c58f1 100644 --- a/futures-util/src/future/abortable.rs +++ b/futures-util/src/future/abortable.rs @@ -3,7 +3,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; @@ -122,7 +122,7 @@ pub struct Aborted; impl Future for Abortable where Fut: Future { type Output = Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { // Check if the future has been aborted if self.inner.cancel.load(Ordering::Relaxed) { return Poll::Ready(Err(Aborted)) diff --git a/futures-util/src/future/catch_unwind.rs b/futures-util/src/future/catch_unwind.rs index 0b26793d50..ec76f44a83 100644 --- a/futures-util/src/future/catch_unwind.rs +++ b/futures-util/src/future/catch_unwind.rs @@ -2,7 +2,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; use std::any::Any; -use std::pin::PinMut; +use std::pin::Pin; use std::panic::{catch_unwind, UnwindSafe, AssertUnwindSafe}; use std::prelude::v1::*; @@ -28,7 +28,7 @@ impl Future for CatchUnwind { type Output = Result>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { match catch_unwind(AssertUnwindSafe(|| self.future().poll(cx))) { Ok(res) => res.map(Ok), Err(e) => Poll::Ready(Err(e)) diff --git a/futures-util/src/future/chain.rs b/futures-util/src/future/chain.rs index 204db279b7..fab30b29f5 100644 --- a/futures-util/src/future/chain.rs +++ b/futures-util/src/future/chain.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -19,7 +19,7 @@ impl Chain } pub(crate) fn poll( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, f: F, ) -> Poll @@ -28,18 +28,18 @@ impl Chain let mut f = Some(f); // Safe to call `get_mut_unchecked` because we won't move the futures. - let this = unsafe { PinMut::get_mut_unchecked(self) }; + let this = unsafe { Pin::get_mut_unchecked(self) }; loop { let (output, data) = match this { Chain::First(fut1, data) => { - match unsafe { PinMut::new_unchecked(fut1) }.poll(cx) { + match unsafe { Pin::new_unchecked(fut1) }.poll(cx) { Poll::Pending => return Poll::Pending, Poll::Ready(output) => (output, data.take().unwrap()), } } Chain::Second(fut2) => { - return unsafe { PinMut::new_unchecked(fut2) }.poll(cx); + return unsafe { Pin::new_unchecked(fut2) }.poll(cx); } Chain::Empty => unreachable!() }; diff --git a/futures-util/src/future/empty.rs b/futures-util/src/future/empty.rs index a5b89b6feb..158af17a4a 100644 --- a/futures-util/src/future/empty.rs +++ b/futures-util/src/future/empty.rs @@ -1,5 +1,5 @@ use core::marker; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -36,7 +36,7 @@ pub fn empty() -> Empty { impl Future for Empty { type Output = T; - fn poll(self: PinMut, _: &mut task::Context) -> Poll { + fn poll(self: Pin<&mut Self>, _: &mut task::Context) -> Poll { Poll::Pending } } diff --git a/futures-util/src/future/flatten.rs b/futures-util/src/future/flatten.rs index 66a131acad..7bb80496db 100644 --- a/futures-util/src/future/flatten.rs +++ b/futures-util/src/future/flatten.rs @@ -1,6 +1,6 @@ use super::chain::Chain; use core::fmt; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -48,7 +48,7 @@ impl Future for Flatten { type Output = ::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.state().poll(cx, |a, ()| a) } } diff --git a/futures-util/src/future/flatten_stream.rs b/futures-util/src/future/flatten_stream.rs index ace1bc7d3d..6c4a4dfdf4 100644 --- a/futures-util/src/future/flatten_stream.rs +++ b/futures-util/src/future/flatten_stream.rs @@ -1,5 +1,5 @@ use core::fmt; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -46,14 +46,14 @@ impl Stream for FlattenStream { type Item = ::Item; - fn poll_next(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { loop { // safety: data is never moved via the resulting &mut reference - let stream = match &mut unsafe { PinMut::get_mut_unchecked(self.reborrow()) }.state { + let stream = match &mut unsafe { Pin::get_mut_unchecked(self.as_mut()) }.state { State::Future(f) => { // safety: the future we're re-pinning here will never be moved; // it will just be polled, then dropped in place - match unsafe { PinMut::new_unchecked(f) }.poll(cx) { + match unsafe { Pin::new_unchecked(f) }.poll(cx) { Poll::Pending => { // State is not changed, early return. return Poll::Pending @@ -69,14 +69,14 @@ impl Stream for FlattenStream State::Stream(s) => { // safety: the stream we're repinning here will never be moved; // it will just be polled, then dropped in place - return unsafe { PinMut::new_unchecked(s) }.poll_next(cx); + return unsafe { Pin::new_unchecked(s) }.poll_next(cx); } }; unsafe { // safety: we use the &mut only for an assignment, which causes // only an in-place drop - PinMut::get_mut_unchecked(self.reborrow()).state = State::Stream(stream); + Pin::get_mut_unchecked(self.as_mut()).state = State::Stream(stream); } } } diff --git a/futures-util/src/future/fuse.rs b/futures-util/src/future/fuse.rs index b421063a3f..4866904c17 100644 --- a/futures-util/src/future/fuse.rs +++ b/futures-util/src/future/fuse.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -29,7 +29,7 @@ impl Fuse { impl Future for Fuse { type Output = Fut::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { // safety: we use this &mut only for matching, not for movement let v = match self.future().as_pin_mut() { Some(fut) => { @@ -42,7 +42,7 @@ impl Future for Fuse { None => return Poll::Pending, }; - PinMut::set(self.future(), None); + Pin::set(self.future(), None); Poll::Ready(v) } } diff --git a/futures-util/src/future/inspect.rs b/futures-util/src/future/inspect.rs index fd8307d419..c5b3644e19 100644 --- a/futures-util/src/future/inspect.rs +++ b/futures-util/src/future/inspect.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -34,7 +34,7 @@ impl Future for Inspect { type Output = Fut::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let e = match self.future().poll(cx) { Poll::Pending => return Poll::Pending, Poll::Ready(e) => e, diff --git a/futures-util/src/future/into_stream.rs b/futures-util/src/future/into_stream.rs index 57e25a00b9..2755d06427 100644 --- a/futures-util/src/future/into_stream.rs +++ b/futures-util/src/future/into_stream.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -25,7 +25,7 @@ impl IntoStream { impl Stream for IntoStream { type Item = Fut::Output; - fn poll_next(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { let v = match self.future().as_pin_mut() { Some(fut) => { match fut.poll(cx) { @@ -36,7 +36,7 @@ impl Stream for IntoStream { None => return Poll::Ready(None), }; - PinMut::set(self.future(), None); + Pin::set(self.future(), None); Poll::Ready(Some(v)) } } diff --git a/futures-util/src/future/join.rs b/futures-util/src/future/join.rs index 1ace2bdac4..4b7dd25869 100644 --- a/futures-util/src/future/join.rs +++ b/futures-util/src/future/join.rs @@ -2,7 +2,7 @@ use crate::future::{MaybeDone, maybe_done}; use core::fmt; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -48,7 +48,7 @@ macro_rules! generate { #[allow(clippy::useless_let_if_seq)] fn poll( - mut self: PinMut, cx: &mut task::Context + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll { let mut all_done = true; $( diff --git a/futures-util/src/future/lazy.rs b/futures-util/src/future/lazy.rs index 90b8aee960..9f0cedf2ee 100644 --- a/futures-util/src/future/lazy.rs +++ b/futures-util/src/future/lazy.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -12,7 +12,7 @@ pub struct Lazy { f: Option } -// safe because we never generate `PinMut` +// safe because we never generate `Pin<&mut F>` impl Unpin for Lazy {} /// Creates a new future that allows delayed execution of a closure. @@ -46,7 +46,7 @@ impl Future for Lazy { type Output = R; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { Poll::Ready((self.f.take().unwrap())(cx)) } } diff --git a/futures-util/src/future/map.rs b/futures-util/src/future/map.rs index b77be1575c..8cc46004ef 100644 --- a/futures-util/src/future/map.rs +++ b/futures-util/src/future/map.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -32,7 +32,7 @@ impl Future for Map { type Output = T; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { match self.future().poll(cx) { Poll::Pending => Poll::Pending, Poll::Ready(output) => { diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index 3ab729c6d4..eb3890bf36 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::mem; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -20,7 +20,7 @@ pub enum MaybeDone { Gone, } -// Safe because we never generate `PinMut` +// Safe because we never generate `Pin<&mut Fut::Output>` impl Unpin for MaybeDone {} /// Wraps a future into a `MaybeDone` @@ -35,10 +35,10 @@ impl Unpin for MaybeDone {} /// /// let future = future::maybe_done(future::ready(5)); /// pin_mut!(future); -/// assert_eq!(future.reborrow().take_output(), None); -/// let () = await!(future.reborrow()); -/// assert_eq!(future.reborrow().take_output(), Some(5)); -/// assert_eq!(future.reborrow().take_output(), None); +/// assert_eq!(future.as_mut().take_output(), None); +/// let () = await!(future.as_mut()); +/// assert_eq!(future.as_mut().take_output(), Some(5)); +/// assert_eq!(future.as_mut().take_output(), None); /// # }); /// ``` pub fn maybe_done(future: Fut) -> MaybeDone { @@ -52,9 +52,9 @@ impl MaybeDone { /// has not yet been called. #[inline] #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn output_mut<'a>(self: PinMut<'a, Self>) -> Option<&'a mut Fut::Output> { + pub fn output_mut<'a>(self: Pin<&'a mut Self>) -> Option<&'a mut Fut::Output> { unsafe { - let this = PinMut::get_mut_unchecked(self); + let this = Pin::get_mut_unchecked(self); match this { MaybeDone::Done(res) => Some(res), _ => None, @@ -65,9 +65,9 @@ impl MaybeDone { /// Attempt to take the output of a `MaybeDone` without driving it /// towards completion. #[inline] - pub fn take_output(self: PinMut) -> Option { + pub fn take_output(self: Pin<&mut Self>) -> Option { unsafe { - let this = PinMut::get_mut_unchecked(self); + let this = Pin::get_mut_unchecked(self); match this { MaybeDone::Done(_) => {}, MaybeDone::Future(_) | MaybeDone::Gone => return None, @@ -84,11 +84,11 @@ impl MaybeDone { impl Future for MaybeDone { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let res = unsafe { - match PinMut::get_mut_unchecked(self.reborrow()) { + match Pin::get_mut_unchecked(self.as_mut()) { MaybeDone::Future(a) => { - if let Poll::Ready(res) = PinMut::new_unchecked(a).poll(cx) { + if let Poll::Ready(res) = Pin::new_unchecked(a).poll(cx) { res } else { return Poll::Pending @@ -98,7 +98,7 @@ impl Future for MaybeDone { MaybeDone::Gone => panic!("MaybeDone polled after value taken"), } }; - PinMut::set(self, MaybeDone::Done(res)); + Pin::set(self, MaybeDone::Done(res)); Poll::Ready(()) } } diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 8597b00dc3..364d227ca3 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -4,7 +4,7 @@ //! including the `FutureExt` trait which adds methods to `Future` types. use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll, Spawn}; @@ -68,8 +68,6 @@ mod chain; pub(crate) use self::chain::Chain; if_std! { - use std::pin::PinBox; - mod abortable; pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted}; @@ -625,10 +623,10 @@ pub trait FutureExt: Future { /// Wrap the future in a Box, pinning it. #[cfg(feature = "std")] - fn boxed(self) -> PinBox + fn boxed(self) -> Pin> where Self: Sized { - PinBox::new(self) + Box::pinned(self) } /// Turns a `Future` into a `TryFuture` with `Error = ()`. @@ -681,7 +679,7 @@ pub trait FutureExt: Future { fn poll_unpin(&mut self, cx: &mut task::Context) -> Poll where Self: Unpin + Sized { - PinMut::new(self).poll(cx) + Pin::new(self).poll(cx) } } diff --git a/futures-util/src/future/option.rs b/futures-util/src/future/option.rs index 787dee5d60..c9a83098f5 100644 --- a/futures-util/src/future/option.rs +++ b/futures-util/src/future/option.rs @@ -1,6 +1,6 @@ //! Definition of the `Option` (optional step) combinator -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -37,7 +37,7 @@ impl Future for OptionFuture { type Output = Option; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll { match self.option().as_pin_mut() { diff --git a/futures-util/src/future/poll_fn.rs b/futures-util/src/future/poll_fn.rs index 80d2a55047..d86920e004 100644 --- a/futures-util/src/future/poll_fn.rs +++ b/futures-util/src/future/poll_fn.rs @@ -1,7 +1,7 @@ //! Definition of the `PollFn` adapter combinator use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -48,7 +48,7 @@ impl Future for PollFn { type Output = T; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { (&mut self.f)(cx) } } diff --git a/futures-util/src/future/ready.rs b/futures-util/src/future/ready.rs index 01b062c34b..ccd96b3d4d 100644 --- a/futures-util/src/future/ready.rs +++ b/futures-util/src/future/ready.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; @@ -16,7 +16,7 @@ impl Future for Ready { type Output = T; #[inline] - fn poll(mut self: PinMut, _cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, _cx: &mut task::Context) -> Poll { Poll::Ready(self.0.take().unwrap()) } } diff --git a/futures-util/src/future/shared.rs b/futures-util/src/future/shared.rs index 7ce1179aa6..a005d3d8ac 100644 --- a/futures-util/src/future/shared.rs +++ b/futures-util/src/future/shared.rs @@ -4,7 +4,7 @@ use slab::Slab; use std::fmt; use std::cell::UnsafeCell; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; @@ -150,7 +150,7 @@ where { type Output = Fut::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let this = &mut *self; this.set_waker(cx); @@ -193,7 +193,7 @@ where // Poll the future let res = unsafe { if let FutureOrOutput::Future(future) = &mut *this.inner.future_or_output.get() { - PinMut::new_unchecked(future).poll(&mut cx) + Pin::new_unchecked(future).poll(&mut cx) } else { unreachable!() } diff --git a/futures-util/src/future/then.rs b/futures-util/src/future/then.rs index 8f735126bf..ae29f442b9 100644 --- a/futures-util/src/future/then.rs +++ b/futures-util/src/future/then.rs @@ -1,5 +1,5 @@ use super::Chain; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -35,7 +35,7 @@ impl Future for Then { type Output = Fut2::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.chain().poll(cx, |output, f| f(output)) } } diff --git a/futures-util/src/future/unit_error.rs b/futures-util/src/future/unit_error.rs index 3b57e9a8f4..d534f95cd4 100644 --- a/futures-util/src/future/unit_error.rs +++ b/futures-util/src/future/unit_error.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -29,7 +29,7 @@ impl Future for UnitError { type Output = Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { self.future().poll(cx).map(Ok) } } diff --git a/futures-util/src/future/with_spawner.rs b/futures-util/src/future/with_spawner.rs index c6d23d6234..9cc60bd42d 100644 --- a/futures-util/src/future/with_spawner.rs +++ b/futures-util/src/future/with_spawner.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll, Spawn}; @@ -28,9 +28,9 @@ impl Future for WithSpawner { type Output = Fut::Output; - fn poll(self: PinMut, cx: &mut task::Context) -> Poll { - let this = unsafe { PinMut::get_mut_unchecked(self) }; - let fut = unsafe { PinMut::new_unchecked(&mut this.future) }; + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + let this = unsafe { Pin::get_mut_unchecked(self) }; + let fut = unsafe { Pin::new_unchecked(&mut this.future) }; let spawner = &mut this.spawner; fut.poll(&mut cx.with_spawner(spawner)) } diff --git a/futures-util/src/io/close.rs b/futures-util/src/io/close.rs index 3d1010f275..e3126ed40e 100644 --- a/futures-util/src/io/close.rs +++ b/futures-util/src/io/close.rs @@ -3,7 +3,7 @@ use futures_core::task::{self, Poll}; use futures_io::AsyncWrite; use std::io; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// A future used to fully close an I/O object. /// @@ -15,7 +15,7 @@ pub struct Close<'a, W: ?Sized + 'a> { writer: &'a mut W, } -// PinMut is never projected to fields +// Pin is never projected to fields impl Unpin for Close<'_, W> {} impl<'a, W: AsyncWrite + ?Sized> Close<'a, W> { @@ -27,7 +27,7 @@ impl<'a, W: AsyncWrite + ?Sized> Close<'a, W> { impl Future for Close<'_, W> { type Output = io::Result<()>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.writer.poll_close(cx) } } diff --git a/futures-util/src/io/copy_into.rs b/futures-util/src/io/copy_into.rs index 601859a7e0..5df0436ae8 100644 --- a/futures-util/src/io/copy_into.rs +++ b/futures-util/src/io/copy_into.rs @@ -4,7 +4,7 @@ use futures_io::{AsyncRead, AsyncWrite}; use std::boxed::Box; use std::io; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// A future which will copy all data from a reader into a writer. /// @@ -23,7 +23,7 @@ pub struct CopyInto<'a, R: ?Sized + 'a, W: ?Sized + 'a> { buf: Box<[u8]>, } -// No projections of PinMut into PinMut are ever done. +// No projections of Pin<&mut CopyInto> into Pin<&mut Field> are ever done. impl Unpin for CopyInto<'_, R, W> {} impl<'a, R: ?Sized, W: ?Sized> CopyInto<'a, R, W> { @@ -46,7 +46,7 @@ impl Future for CopyInto<'_, R, W> { type Output = io::Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let this = &mut *self; loop { // If our buffer is empty, then we need to read some data to diff --git a/futures-util/src/io/flush.rs b/futures-util/src/io/flush.rs index aba347599a..b83293e177 100644 --- a/futures-util/src/io/flush.rs +++ b/futures-util/src/io/flush.rs @@ -2,7 +2,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; use std::io; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use futures_io::AsyncWrite; @@ -32,7 +32,7 @@ impl Future for Flush<'_, W> { type Output = io::Result<()>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.writer.poll_flush(cx) } } diff --git a/futures-util/src/io/read.rs b/futures-util/src/io/read.rs index 5a30cd7395..6b0e878692 100644 --- a/futures-util/src/io/read.rs +++ b/futures-util/src/io/read.rs @@ -3,7 +3,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll}; use std::io; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// A future which can be used to easily read available number of bytes to fill /// a buffer. @@ -25,7 +25,7 @@ impl<'a, R: AsyncRead + ?Sized> Read<'a, R> { impl Future for Read<'_, R> { type Output = io::Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let this = &mut *self; this.reader.poll_read(cx, this.buf) } diff --git a/futures-util/src/io/read_exact.rs b/futures-util/src/io/read_exact.rs index 4a34ea70cb..f16cc46f5e 100644 --- a/futures-util/src/io/read_exact.rs +++ b/futures-util/src/io/read_exact.rs @@ -4,7 +4,7 @@ use futures_core::task::{self, Poll}; use std::io; use std::marker::Unpin; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; /// A future which can be used to easily read exactly enough bytes to fill /// a buffer. @@ -33,7 +33,7 @@ fn eof() -> io::Error { impl Future for ReadExact<'_, R> { type Output = io::Result<()>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let this = &mut *self; while !this.buf.is_empty() { let n = try_ready!(this.reader.poll_read(cx, this.buf)); diff --git a/futures-util/src/io/read_to_end.rs b/futures-util/src/io/read_to_end.rs index 1294e7be08..55bd3dec3a 100644 --- a/futures-util/src/io/read_to_end.rs +++ b/futures-util/src/io/read_to_end.rs @@ -3,7 +3,7 @@ use futures_core::task::{self, Poll}; use futures_io::AsyncRead; use std::io; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::vec::Vec; /// A future which can be used to easily read the entire contents of a stream @@ -83,7 +83,7 @@ impl Future for ReadToEnd<'_, A> { type Output = io::Result<()>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { let this = &mut *self; read_to_end_internal(this.reader, cx, this.buf) } diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index 4f1e84b9b9..d5676bdc0e 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -2,7 +2,7 @@ use crate::lock::BiLock; use futures_core::task::{self, Poll}; use futures_io::{AsyncRead, AsyncWrite, IoVec}; use std::io; -use std::pin::PinMut; +use std::pin::Pin; /// The readable half of an object returned from `AsyncRead::split`. #[derive(Debug)] @@ -25,8 +25,8 @@ fn lock_and_then( { match lock.poll_lock(cx) { // Safety: the value behind the bilock used by `ReadHalf` and `WriteHalf` is never exposed - // as a `PinMut` anywhere other than here as a way to get to `&mut`. - Poll::Ready(mut l) => f(unsafe { PinMut::get_mut_unchecked(l.as_pin_mut()) }, cx), + // as a `Pin<&mut T>` anywhere other than here as a way to get to `&mut T`. + Poll::Ready(mut l) => f(unsafe { Pin::get_mut_unchecked(l.as_pin_mut()) }, cx), Poll::Pending => Poll::Pending, } } diff --git a/futures-util/src/io/write_all.rs b/futures-util/src/io/write_all.rs index f8147ade30..e20912d031 100644 --- a/futures-util/src/io/write_all.rs +++ b/futures-util/src/io/write_all.rs @@ -4,7 +4,7 @@ use futures_io::AsyncWrite; use std::io; use std::marker::Unpin; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; /// A future used to write the entire contents of some data to a stream. /// @@ -33,7 +33,7 @@ fn zero_write() -> io::Error { impl Future for WriteAll<'_, W> { type Output = io::Result<()>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { let this = &mut *self; while !this.buf.is_empty() { let n = try_ready!(this.writer.poll_write(cx, this.buf)); diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index 56ac3c65ad..33fb5787ab 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -36,28 +36,28 @@ pub mod core_reexport { macro_rules! delegate_sink { ($field:ident) => { fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut $crate::core_reexport::task::Context, ) -> $crate::core_reexport::task::Poll> { self.$field().poll_ready(cx) } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem ) -> Result<(), Self::SinkError> { self.$field().start_send(item) } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut $crate::core_reexport::task::Context ) -> $crate::core_reexport::task::Poll> { self.$field().poll_flush(cx) } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut $crate::core_reexport::task::Context ) -> $crate::core_reexport::task::Poll> { self.$field().poll_close(cx) diff --git a/futures-util/src/lock.rs b/futures-util/src/lock.rs index 773b583517..dbff4847a0 100644 --- a/futures-util/src/lock.rs +++ b/futures-util/src/lock.rs @@ -11,7 +11,7 @@ use std::fmt; use std::marker::Unpin; use std::mem; use std::ops::{Deref, DerefMut}; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; @@ -55,9 +55,9 @@ impl BiLock { /// that will ever be available to the lock. These can then be sent to separate /// tasks to be managed there. /// - /// The data behind the bilock is considered to be pinned, which allows `PinMut` + /// The data behind the bilock is considered to be pinned, which allows `Pin` /// references to locked data. However, this means that the locked value - /// will only be available through `PinMut` (not `&mut`) unless `T` is `Unpin`. + /// will only be available through `Pin<&mut T>` (not `&mut T`) unless `T` is `Unpin`. /// Similarly, reuniting the lock and extracting the inner value is only /// possible when `T` is `Unpin`. pub fn new(t: T) -> (BiLock, BiLock) { @@ -242,10 +242,10 @@ impl<'a, T: Unpin> DerefMut for BiLockGuard<'a, T> { impl<'a, T> BiLockGuard<'a, T> { /// Get a mutable pinned reference to the locked value. - pub fn as_pin_mut(&mut self) -> PinMut<'_, T> { + pub fn as_pin_mut(&mut self) -> Pin<&mut T> { // Safety: we never allow moving a !Unpin value out of a bilock, nor // allow mutable access to it - unsafe { PinMut::new_unchecked(&mut *self.bilock.arc.value.as_ref().unwrap().get()) } + unsafe { Pin::new_unchecked(&mut *self.bilock.arc.value.as_ref().unwrap().get()) } } } @@ -269,7 +269,7 @@ impl<'a, T> Unpin for BiLockAcquire<'a, T> {} impl<'a, T> Future for BiLockAcquire<'a, T> { type Output = BiLockGuard<'a, T>; - fn poll(self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.bilock.poll_lock(cx) } } diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index 44d7736326..df0d5ae5f1 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -4,7 +4,7 @@ use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::collections::VecDeque; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// Sink for the `Sink::buffer` combinator, which buffers up to some fixed /// number of values when the underlying sink is unable to accept them. @@ -40,7 +40,7 @@ impl Buffer { } fn try_empty_buffer( - self: &mut PinMut, + self: &mut Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { try_ready!(self.sink().poll_ready(cx)); @@ -60,7 +60,7 @@ impl Buffer { impl Stream for Buffer where S: Sink + Stream { type Item = S::Item; - fn poll_next(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { self.sink().poll_next(cx) } } @@ -70,7 +70,7 @@ impl Sink for Buffer { type SinkError = Si::SinkError; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.capacity() == 0 { @@ -89,7 +89,7 @@ impl Sink for Buffer { } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { if *self.capacity() == 0 { @@ -101,7 +101,7 @@ impl Sink for Buffer { } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { try_ready!(self.try_empty_buffer(cx)); @@ -110,7 +110,7 @@ impl Sink for Buffer { } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { try_ready!(self.try_empty_buffer(cx)); diff --git a/futures-util/src/sink/close.rs b/futures-util/src/sink/close.rs index e88cf2a0bc..638d8a9a38 100644 --- a/futures-util/src/sink/close.rs +++ b/futures-util/src/sink/close.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -25,9 +25,9 @@ impl Future for Close<'_, Si> { type Output = Result<(), Si::SinkError>; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { - PinMut::new(&mut self.sink).poll_close(cx) + Pin::new(&mut self.sink).poll_close(cx) } } diff --git a/futures-util/src/sink/drain.rs b/futures-util/src/sink/drain.rs index cbc56aa64e..42827ec3a2 100644 --- a/futures-util/src/sink/drain.rs +++ b/futures-util/src/sink/drain.rs @@ -1,6 +1,6 @@ use core::fmt; use core::marker::PhantomData; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -42,28 +42,28 @@ impl Sink for Drain { type SinkError = DrainError; fn poll_ready( - self: PinMut, + self: Pin<&mut Self>, _cx: &mut task::Context, ) -> Poll> { Poll::Ready(Ok(())) } fn start_send( - self: PinMut, + self: Pin<&mut Self>, _item: Self::SinkItem, ) -> Result<(), Self::SinkError> { Ok(()) } fn poll_flush( - self: PinMut, + self: Pin<&mut Self>, _cx: &mut task::Context, ) -> Poll> { Poll::Ready(Ok(())) } fn poll_close( - self: PinMut, + self: Pin<&mut Self>, _cx: &mut task::Context, ) -> Poll> { Poll::Ready(Ok(())) diff --git a/futures-util/src/sink/err_into.rs b/futures-util/src/sink/err_into.rs index 4d17738f71..ece8285898 100644 --- a/futures-util/src/sink/err_into.rs +++ b/futures-util/src/sink/err_into.rs @@ -1,5 +1,5 @@ use crate::sink::{SinkExt, SinkMapErr}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use futures_sink::{Sink}; @@ -62,7 +62,7 @@ impl Stream for SinkErrInto type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_next(cx) diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index 87a39f8f2c..aab4cb8a64 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -1,5 +1,5 @@ use core::fmt::{Debug, Formatter, Result as FmtResult}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::task::{self, Poll}; use futures_sink::Sink; use pin_utils::unsafe_pinned; @@ -51,7 +51,7 @@ impl Sink for Fanout type SinkError = Si1::SinkError; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_ready(cx)).is_ready(); @@ -61,7 +61,7 @@ impl Sink for Fanout } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { self.sink1().start_send(item.clone())?; @@ -70,7 +70,7 @@ impl Sink for Fanout } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_flush(cx)).is_ready(); @@ -80,7 +80,7 @@ impl Sink for Fanout } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_close(cx)).is_ready(); diff --git a/futures-util/src/sink/flush.rs b/futures-util/src/sink/flush.rs index 42ef6ef957..cf6ddfa8be 100644 --- a/futures-util/src/sink/flush.rs +++ b/futures-util/src/sink/flush.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -31,9 +31,9 @@ impl Future for Flush<'_, Si> { type Output = Result<(), Si::SinkError>; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { - PinMut::new(&mut self.sink).poll_flush(cx) + Pin::new(&mut self.sink).poll_flush(cx) } } diff --git a/futures-util/src/sink/map_err.rs b/futures-util/src/sink/map_err.rs index 15bc044647..cda888b080 100644 --- a/futures-util/src/sink/map_err.rs +++ b/futures-util/src/sink/map_err.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use futures_sink::{Sink}; @@ -35,8 +35,8 @@ impl SinkMapErr { /// Get a pinned reference to the inner sink. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn get_pin_mut<'a>(self: PinMut<'a, Self>) -> PinMut<'a, Si> { - unsafe { PinMut::map_unchecked(self, |x| &mut x.sink) } + pub fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut Si> { + unsafe { Pin::map_unchecked_mut(self, |x| &mut x.sink) } } /// Consumes this combinator, returning the underlying sink. @@ -47,7 +47,7 @@ impl SinkMapErr { self.sink } - fn take_f(mut self: PinMut) -> F { + fn take_f(mut self: Pin<&mut Self>) -> F { self.f().take().expect("polled MapErr after completion") } } @@ -60,7 +60,7 @@ impl Sink for SinkMapErr type SinkError = E; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 @@ -68,7 +68,7 @@ impl Sink for SinkMapErr } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 @@ -76,7 +76,7 @@ impl Sink for SinkMapErr } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 @@ -84,7 +84,7 @@ impl Sink for SinkMapErr } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 @@ -96,7 +96,7 @@ impl Stream for SinkMapErr { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_next(cx) diff --git a/futures-util/src/sink/send.rs b/futures-util/src/sink/send.rs index 3d09e3d9a4..34ca7d663f 100644 --- a/futures-util/src/sink/send.rs +++ b/futures-util/src/sink/send.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -29,15 +29,15 @@ impl Future for Send<'_, Si> { type Output = Result<(), Si::SinkError>; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { let this = &mut *self; if let Some(item) = this.item.take() { - let mut sink = PinMut::new(this.sink); - match sink.reborrow().poll_ready(cx) { + let mut sink = Pin::new(&mut this.sink); + match sink.as_mut().poll_ready(cx) { Poll::Ready(Ok(())) => { - if let Err(e) = sink.reborrow().start_send(item) { + if let Err(e) = sink.as_mut().start_send(item) { return Poll::Ready(Err(e)); } } @@ -51,7 +51,7 @@ impl Future for Send<'_, Si> { // we're done sending the item, but want to block on flushing the // sink - try_ready!(PinMut::new(this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(cx)); Poll::Ready(Ok(())) } diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index f6f57381c8..2d5474d68b 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -1,6 +1,6 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -49,9 +49,9 @@ where item: Si::SinkItem, ) -> Poll> { debug_assert!(self.buffered.is_none()); - match PinMut::new(self.sink).poll_ready(cx) { + match Pin::new(&mut self.sink).poll_ready(cx) { Poll::Ready(Ok(())) => { - Poll::Ready(PinMut::new(self.sink).start_send(item)) + Poll::Ready(Pin::new(&mut self.sink).start_send(item)) } Poll::Ready(Err(e)) => Poll::Ready(Err(e)), Poll::Pending => { @@ -70,7 +70,7 @@ where type Output = Result<(), Si::SinkError>; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { let this = &mut *self; @@ -86,11 +86,11 @@ where try_ready!(this.try_start_send(cx, item)) } Poll::Ready(None) => { - try_ready!(PinMut::new(this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(cx)); return Poll::Ready(Ok(())) } Poll::Pending => { - try_ready!(PinMut::new(this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(cx)); return Poll::Pending } } diff --git a/futures-util/src/sink/with.rs b/futures-util/src/sink/with.rs index dc8f06416e..98722987c5 100644 --- a/futures-util/src/sink/with.rs +++ b/futures-util/src/sink/with.rs @@ -1,6 +1,6 @@ use core::marker::{Unpin, PhantomData}; use core::mem; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -63,16 +63,16 @@ impl State { #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 #[allow(clippy::wrong_self_convention)] fn as_pin_mut<'a>( - self: PinMut<'a, Self>, - ) -> State, PinMut<'a, T>> { + self: Pin<&'a mut Self>, + ) -> State, Pin<&'a mut T>> { unsafe { - match PinMut::get_mut_unchecked(self) { + match Pin::get_mut_unchecked(self) { State::Empty => State::Empty, State::Process(fut) => - State::Process(PinMut::new_unchecked(fut)), + State::Process(Pin::new_unchecked(fut)), State::Buffered(item) => - State::Buffered(PinMut::new_unchecked(item)), + State::Buffered(Pin::new_unchecked(item)), } } } @@ -87,7 +87,7 @@ impl Stream for With type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_next(cx) @@ -119,7 +119,7 @@ impl With } fn poll( - self: &mut PinMut, + self: &mut Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let buffered = match self.state().as_pin_mut() { @@ -128,9 +128,9 @@ impl With State::Buffered(_) => None, }; if let Some(buffered) = buffered { - PinMut::set(self.state(), State::Buffered(buffered)); + Pin::set(self.state(), State::Buffered(buffered)); } - if let State::Buffered(item) = unsafe { mem::replace(PinMut::get_mut_unchecked(self.state()), State::Empty) } { + if let State::Buffered(item) = unsafe { mem::replace(Pin::get_mut_unchecked(self.state()), State::Empty) } { Poll::Ready(self.sink().start_send(item).map_err(Into::into)) } else { unreachable!() @@ -148,23 +148,23 @@ impl Sink for With type SinkError = E; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.poll(cx) } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { let item = (self.f())(item); - PinMut::set(self.state(), State::Process(item)); + Pin::set(self.state(), State::Process(item)); Ok(()) } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { try_ready!(self.poll(cx)); @@ -173,7 +173,7 @@ impl Sink for With } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { try_ready!(self.poll(cx)); diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 15cb902377..1e692f57b3 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -1,5 +1,5 @@ use core::marker::{Unpin, PhantomData}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -62,8 +62,8 @@ where /// Get a pinned mutable reference to the inner sink. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn get_pin_mut<'a>(self: PinMut<'a, Self>) -> PinMut<'a, Si> { - unsafe { PinMut::map_unchecked(self, |x| &mut x.sink) } + pub fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut Si> { + unsafe { Pin::map_unchecked_mut(self, |x| &mut x.sink) } } /// Consumes this combinator, returning the underlying sink. @@ -75,25 +75,25 @@ where } fn try_empty_stream( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let WithFlatMap { sink, stream, buffer, .. } = - unsafe { PinMut::get_mut_unchecked(self) }; - let mut sink = unsafe { PinMut::new_unchecked(sink) }; - let mut stream = unsafe { PinMut::new_unchecked(stream) }; + unsafe { Pin::get_mut_unchecked(self) }; + let mut sink = unsafe { Pin::new_unchecked(sink) }; + let mut stream = unsafe { Pin::new_unchecked(stream) }; if buffer.is_some() { - try_ready!(sink.reborrow().poll_ready(cx)); + try_ready!(sink.as_mut().poll_ready(cx)); let item = buffer.take().unwrap(); - try_ready!(Poll::Ready(sink.reborrow().start_send(item))); + try_ready!(Poll::Ready(sink.as_mut().start_send(item))); } - if let Some(mut some_stream) = stream.reborrow().as_pin_mut() { - while let Some(x) = ready!(some_stream.reborrow().poll_next(cx)) { + if let Some(mut some_stream) = stream.as_mut().as_pin_mut() { + while let Some(x) = ready!(some_stream.as_mut().poll_next(cx)) { let item = try_ready!(Poll::Ready(x)); - match try_poll!(sink.reborrow().poll_ready(cx)) { + match try_poll!(sink.as_mut().poll_ready(cx)) { Poll::Ready(()) => { - try_poll!(Poll::Ready(sink.reborrow().start_send(item))) + try_poll!(Poll::Ready(sink.as_mut().start_send(item))) } Poll::Pending => { *buffer = Some(item); @@ -102,7 +102,7 @@ where }; } } - PinMut::set(stream, None); + Pin::set(stream, None); Poll::Ready(Ok(())) } } @@ -115,7 +115,7 @@ where { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_next(cx) @@ -132,27 +132,27 @@ where type SinkError = Si::SinkError; fn poll_ready( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.try_empty_stream(cx) } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { assert!(self.stream().is_none()); let stream = (self.f())(item); - PinMut::set(self.stream(), Some(stream)); + Pin::set(self.stream(), Some(stream)); Ok(()) } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - match self.reborrow().try_empty_stream(cx) { + match self.as_mut().try_empty_stream(cx) { Poll::Pending => Poll::Pending, Poll::Ready(Ok(())) => self.sink().poll_flush(cx), Poll::Ready(Err(e)) => Poll::Ready(Err(e)), @@ -160,10 +160,10 @@ where } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - match self.reborrow().try_empty_stream(cx) { + match self.as_mut().try_empty_stream(cx) { Poll::Pending => Poll::Pending, Poll::Ready(Ok(())) => self.sink().poll_close(cx), Poll::Ready(Err(e)) => Poll::Ready(Err(e)), diff --git a/futures-util/src/stream/buffer_unordered.rs b/futures-util/src/stream/buffer_unordered.rs index 3455f2030f..28864c20e8 100644 --- a/futures-util/src/stream/buffer_unordered.rs +++ b/futures-util/src/stream/buffer_unordered.rs @@ -6,7 +6,7 @@ use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::fmt; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// An adaptor for a stream of futures to execute the futures concurrently, if /// possible, delivering results as they become available. @@ -86,8 +86,8 @@ where /// Note that care must be taken to avoid tampering with the state of the /// stream which may otherwise confuse this combinator. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn get_pin_mut<'a>(self: PinMut<'a, Self>) -> PinMut<'a, St> { - unsafe { PinMut::map_unchecked(self, |x| x.get_mut()) } + pub fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut St> { + unsafe { Pin::map_unchecked_mut(self, |x| x.get_mut()) } } /// Consumes this combinator, returning the underlying stream. @@ -107,7 +107,7 @@ where type Item = ::Output; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { // First up, try to spawn off as many futures as possible by filling up @@ -120,7 +120,7 @@ where } // Attempt to pull the next value from the in_progress_queue - match PinMut::new(self.in_progress_queue()).poll_next(cx) { + match Pin::new(self.in_progress_queue()).poll_next(cx) { x @ Poll::Pending | x @ Poll::Ready(Some(_)) => return x, Poll::Ready(None) => {} } diff --git a/futures-util/src/stream/buffered.rs b/futures-util/src/stream/buffered.rs index a3bf487b4c..6fab7f66d1 100644 --- a/futures-util/src/stream/buffered.rs +++ b/futures-util/src/stream/buffered.rs @@ -6,7 +6,7 @@ use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::fmt; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// An adaptor for a stream of futures to execute the futures concurrently, if /// possible. @@ -82,8 +82,8 @@ where /// Note that care must be taken to avoid tampering with the state of the /// stream which may otherwise confuse this combinator. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn get_pin_mut<'a>(self: PinMut<'a, Self>) -> PinMut<'a, St> { - unsafe { PinMut::map_unchecked(self, |x| x.get_mut()) } + pub fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut St> { + unsafe { Pin::map_unchecked_mut(self, |x| x.get_mut()) } } /// Consumes this combinator, returning the underlying stream. @@ -103,7 +103,7 @@ where type Item = ::Output; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { // Try to spawn off as many futures as possible by filling up @@ -116,7 +116,7 @@ where } // Attempt to pull the next value from the in_progress_queue - let res = PinMut::new(self.in_progress_queue()).poll_next(cx); + let res = Pin::new(self.in_progress_queue()).poll_next(cx); if let Some(val) = ready!(res) { return Poll::Ready(Some(val)) } diff --git a/futures-util/src/stream/catch_unwind.rs b/futures-util/src/stream/catch_unwind.rs index 579fa34478..58a572b3f5 100644 --- a/futures-util/src/stream/catch_unwind.rs +++ b/futures-util/src/stream/catch_unwind.rs @@ -2,7 +2,7 @@ use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::any::Any; -use std::pin::PinMut; +use std::pin::Pin; use std::panic::{catch_unwind, UnwindSafe, AssertUnwindSafe}; use std::prelude::v1::*; @@ -30,7 +30,7 @@ impl Stream for CatchUnwind type Item = Result>; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.caught_unwind() { diff --git a/futures-util/src/stream/chain.rs b/futures-util/src/stream/chain.rs index 0da35f4ab4..ba12a74d93 100644 --- a/futures-util/src/stream/chain.rs +++ b/futures-util/src/stream/chain.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -14,7 +14,7 @@ pub struct Chain { second: St2, } -// All interactions with `PinMut>` happen through these methods +// All interactions with `Pin<&mut Chain<..>>` happen through these methods impl Chain where St1: Stream, St2: Stream, @@ -37,7 +37,7 @@ where St1: Stream, type Item = St1::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if let Some(first) = self.first().as_pin_mut() { @@ -45,7 +45,7 @@ where St1: Stream, return Poll::Ready(Some(item)) } } - PinMut::set(self.first(), None); + Pin::set(self.first(), None); self.second().poll_next(cx) } } diff --git a/futures-util/src/stream/chunks.rs b/futures-util/src/stream/chunks.rs index 9aecc9542e..240bfd7e8c 100644 --- a/futures-util/src/stream/chunks.rs +++ b/futures-util/src/stream/chunks.rs @@ -4,7 +4,7 @@ use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; use std::prelude::v1::*; /// An adaptor that chunks up elements in a vector. @@ -34,7 +34,7 @@ impl Chunks where St: Stream { } } - fn take(mut self: PinMut) -> Vec { + fn take(mut self: Pin<&mut Self>) -> Vec { let cap = self.items().capacity(); mem::replace(self.items(), Vec::with_capacity(cap)) } @@ -67,7 +67,7 @@ impl Stream for Chunks { type Item = Vec; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let cap = self.items.capacity(); diff --git a/futures-util/src/stream/collect.rs b/futures-util/src/stream/collect.rs index 991d6fbb68..acc46228d1 100644 --- a/futures-util/src/stream/collect.rs +++ b/futures-util/src/stream/collect.rs @@ -4,7 +4,7 @@ use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; use std::prelude::v1::*; /// A future which collects all of the values of a stream into a vector. @@ -23,7 +23,7 @@ impl Collect { unsafe_pinned!(stream: St); unsafe_unpinned!(collection: C); - fn finish(mut self: PinMut) -> C { + fn finish(mut self: Pin<&mut Self>) -> C { mem::replace(self.collection(), Default::default()) } @@ -41,7 +41,7 @@ where St: Stream, { type Output = C; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { loop { match ready!(self.stream().poll_next(cx)) { Some(e) => self.collection().extend(Some(e)), diff --git a/futures-util/src/stream/concat.rs b/futures-util/src/stream/concat.rs index 39a7ac8278..cae3713e7e 100644 --- a/futures-util/src/stream/concat.rs +++ b/futures-util/src/stream/concat.rs @@ -1,6 +1,6 @@ use core::fmt::{Debug, Formatter, Result as FmtResult}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use core::default::Default; use futures_core::future::Future; use futures_core::stream::Stream; @@ -54,7 +54,7 @@ where St: Stream, type Output = St::Item; fn poll( - mut self: PinMut, cx: &mut task::Context + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll { loop { match self.stream().poll_next(cx) { diff --git a/futures-util/src/stream/disabled/select_all.rs b/futures-util/src/stream/disabled/select_all.rs index 5360402494..17cc6911d8 100644 --- a/futures-util/src/stream/disabled/select_all.rs +++ b/futures-util/src/stream/disabled/select_all.rs @@ -1,7 +1,7 @@ //! An unbounded set of streams use std::fmt::{self, Debug}; -use std::pin::PinMut; +use std::pin::Pin; use futures_core::{Poll, Stream}; use futures_core::task; diff --git a/futures-util/src/stream/empty.rs b/futures-util/src/stream/empty.rs index 5571c64ff2..7b1bf2597c 100644 --- a/futures-util/src/stream/empty.rs +++ b/futures-util/src/stream/empty.rs @@ -1,5 +1,5 @@ use core::marker::{Unpin, PhantomData}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -26,7 +26,7 @@ impl Unpin for Empty {} impl Stream for Empty { type Item = T; - fn poll_next(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(None) } } diff --git a/futures-util/src/stream/filter.rs b/futures-util/src/stream/filter.rs index 75489fc019..67518e8fd7 100644 --- a/futures-util/src/stream/filter.rs +++ b/futures-util/src/stream/filter.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -79,7 +79,7 @@ impl Stream for Filter type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { loop { @@ -89,12 +89,12 @@ impl Stream for Filter None => return Poll::Ready(None), }; let fut = (self.f())(&item); - PinMut::set(self.pending_fut(), Some(fut)); + Pin::set(self.pending_fut(), Some(fut)); *self.pending_item() = Some(item); } let yield_item = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); - PinMut::set(self.pending_fut(), None); + Pin::set(self.pending_fut(), None); let item = self.pending_item().take().unwrap(); if yield_item { diff --git a/futures-util/src/stream/filter_map.rs b/futures-util/src/stream/filter_map.rs index acb642396d..0feddb87c9 100644 --- a/futures-util/src/stream/filter_map.rs +++ b/futures-util/src/stream/filter_map.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -72,7 +72,7 @@ impl Stream for FilterMap type Item = T; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { loop { @@ -82,11 +82,11 @@ impl Stream for FilterMap None => return Poll::Ready(None), }; let fut = (self.f())(item); - PinMut::set(self.pending(), Some(fut)); + Pin::set(self.pending(), Some(fut)); } let item = ready!(self.pending().as_pin_mut().unwrap().poll(cx)); - PinMut::set(self.pending(), None); + Pin::set(self.pending(), None); if item.is_some() { return Poll::Ready(item); } diff --git a/futures-util/src/stream/flatten.rs b/futures-util/src/stream/flatten.rs index cd70f72100..bffb283eb8 100644 --- a/futures-util/src/stream/flatten.rs +++ b/futures-util/src/stream/flatten.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -64,13 +64,13 @@ impl Stream for Flatten type Item = ::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { loop { if self.next().as_pin_mut().is_none() { match ready!(self.stream().poll_next(cx)) { - Some(e) => PinMut::set(self.next(), Some(e)), + Some(e) => Pin::set(self.next(), Some(e)), None => return Poll::Ready(None), } } @@ -78,7 +78,7 @@ impl Stream for Flatten if item.is_some() { return Poll::Ready(item); } else { - PinMut::set(self.next(), None); + Pin::set(self.next(), None); } } } diff --git a/futures-util/src/stream/fold.rs b/futures-util/src/stream/fold.rs index bb2e8fb974..9913244ba8 100644 --- a/futures-util/src/stream/fold.rs +++ b/futures-util/src/stream/fold.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -46,13 +46,13 @@ impl Future for Fold { type Output = T; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { loop { // we're currently processing a future to produce a new accum value if self.accum().is_none() { let accum = ready!(self.future().as_pin_mut().unwrap().poll(cx)); *self.accum() = Some(accum); - PinMut::set(self.future(), None); + Pin::set(self.future(), None); } let item = ready!(self.stream().poll_next(cx)); @@ -61,7 +61,7 @@ impl Future for Fold if let Some(e) = item { let future = (self.f())(accum, e); - PinMut::set(self.future(), Some(future)); + Pin::set(self.future(), Some(future)); } else { return Poll::Ready(accum) } diff --git a/futures-util/src/stream/for_each.rs b/futures-util/src/stream/for_each.rs index a7296b8aa9..5f45b84601 100644 --- a/futures-util/src/stream/for_each.rs +++ b/futures-util/src/stream/for_each.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -48,17 +48,17 @@ impl Future for ForEach { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { loop { if let Some(future) = self.future().as_pin_mut() { ready!(future.poll(cx)); } - PinMut::set(self.future(), None); + Pin::set(self.future(), None); match ready!(self.stream().poll_next(cx)) { Some(e) => { let future = (self.f())(e); - PinMut::set(self.future(), Some(future)); + Pin::set(self.future(), Some(future)); } None => { return Poll::Ready(()); diff --git a/futures-util/src/stream/for_each_concurrent.rs b/futures-util/src/stream/for_each_concurrent.rs index 5363a9e526..ac47aa0c15 100644 --- a/futures-util/src/stream/for_each_concurrent.rs +++ b/futures-util/src/stream/for_each_concurrent.rs @@ -1,6 +1,6 @@ use crate::stream::{FuturesUnordered, StreamExt}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use core::num::NonZeroUsize; use futures_core::future::Future; use futures_core::stream::Stream; @@ -55,7 +55,7 @@ impl Future for ForEachConcurrent { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { loop { let mut made_progress_this_iter = false; @@ -80,7 +80,7 @@ impl Future for ForEachConcurrent None }; if stream_completed { - PinMut::set(self.stream(), None); + Pin::set(self.stream(), None); } if let Some(elem) = elem { let next_future = (self.f())(elem); diff --git a/futures-util/src/stream/forward.rs b/futures-util/src/stream/forward.rs index ab6bc32fb9..4639f7b322 100644 --- a/futures-util/src/stream/forward.rs +++ b/futures-util/src/stream/forward.rs @@ -1,6 +1,6 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -45,14 +45,14 @@ where } fn try_start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, item: Si::SinkItem, ) -> Poll> { debug_assert!(self.buffered_item.is_none()); { let mut sink = self.sink().as_pin_mut().unwrap(); - if try_poll!(sink.reborrow().poll_ready(cx)).is_ready() { + if try_poll!(sink.as_mut().poll_ready(cx)).is_ready() { return Poll::Ready(sink.start_send(item)); } } @@ -69,19 +69,19 @@ where type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { // If we've got an item buffered already, we need to write it to the // sink before we can do anything else if let Some(item) = self.buffered_item().take() { - try_ready!(self.reborrow().try_start_send(cx, item)); + try_ready!(self.as_mut().try_start_send(cx, item)); } loop { match self.stream().poll_next(cx) { Poll::Ready(Some(Ok(item))) => - try_ready!(self.reborrow().try_start_send(cx, item)), + try_ready!(self.as_mut().try_start_send(cx, item)), Poll::Ready(Some(Err(e))) => return Poll::Ready(Err(e)), Poll::Ready(None) => { try_ready!(self.sink().as_pin_mut().expect(INVALID_POLL) diff --git a/futures-util/src/stream/fuse.rs b/futures-util/src/stream/fuse.rs index 3550d83b41..37474a6c69 100644 --- a/futures-util/src/stream/fuse.rs +++ b/futures-util/src/stream/fuse.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -57,8 +57,8 @@ impl Fuse { /// Note that care must be taken to avoid tampering with the state of the /// stream which may otherwise confuse this combinator. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn get_pin_mut<'a>(self: PinMut<'a, Self>) -> PinMut<'a, St> { - unsafe { PinMut::map_unchecked(self, |x| x.get_mut()) } + pub fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut St> { + unsafe { Pin::map_unchecked_mut(self, |x| x.get_mut()) } } /// Consumes this combinator, returning the underlying stream. @@ -74,7 +74,7 @@ impl Stream for Fuse { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.done() { diff --git a/futures-util/src/stream/futures_ordered.rs b/futures-util/src/stream/futures_ordered.rs index 857577e627..52cfb64d56 100644 --- a/futures-util/src/stream/futures_ordered.rs +++ b/futures-util/src/stream/futures_ordered.rs @@ -8,7 +8,7 @@ use std::collections::binary_heap::{BinaryHeap, PeekMut}; use std::fmt::{self, Debug}; use std::iter::FromIterator; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; #[must_use = "futures do nothing unless polled"] #[derive(Debug)] @@ -48,7 +48,7 @@ impl Future for OrderWrapper type Output = OrderWrapper; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { self.data().poll(cx) @@ -171,7 +171,7 @@ impl Stream for FuturesOrdered { type Item = Fut::Output; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { let this = &mut *self; @@ -185,7 +185,7 @@ impl Stream for FuturesOrdered { } loop { - match PinMut::new(&mut this.in_progress_queue).poll_next(cx) { + match Pin::new(&mut this.in_progress_queue).poll_next(cx) { Poll::Ready(Some(output)) => { if output.index == this.next_outgoing_index { this.next_outgoing_index += 1; diff --git a/futures-util/src/stream/futures_unordered/iter.rs b/futures-util/src/stream/futures_unordered/iter.rs index 53ca3341f2..7f467c062f 100644 --- a/futures-util/src/stream/futures_unordered/iter.rs +++ b/futures-util/src/stream/futures_unordered/iter.rs @@ -1,7 +1,7 @@ use super::FuturesUnordered; use super::task::Task; use std::marker::{PhantomData, Unpin}; -use std::pin::PinMut; +use std::pin::Pin; #[derive(Debug)] /// Mutable iterator over all futures in the unordered set. @@ -16,9 +16,9 @@ pub struct IterPinMut<'a, Fut: 'a> { pub struct IterMut<'a, Fut: Unpin + 'a> (pub(super) IterPinMut<'a, Fut>); impl<'a, Fut> Iterator for IterPinMut<'a, Fut> { - type Item = PinMut<'a, Fut>; + type Item = Pin<&'a mut Fut>; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { if self.task.is_null() { return None; } @@ -27,7 +27,7 @@ impl<'a, Fut> Iterator for IterPinMut<'a, Fut> { let next = *(*self.task).next_all.get(); self.task = next; self.len -= 1; - Some(PinMut::new_unchecked(future)) + Some(Pin::new_unchecked(future)) } } @@ -42,7 +42,7 @@ impl<'a, Fut: Unpin> Iterator for IterMut<'a, Fut> { type Item = &'a mut Fut; fn next(&mut self) -> Option<&'a mut Fut> { - self.0.next().map(PinMut::get_mut) + self.0.next().map(Pin::get_mut) } fn size_hint(&self) -> (usize, Option) { diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index b1102ca59f..fda65f2684 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -9,7 +9,7 @@ use std::fmt::{self, Debug}; use std::iter::FromIterator; use std::marker::{PhantomData, Unpin}; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; use std::ptr; use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicPtr, AtomicBool}; @@ -158,12 +158,12 @@ impl FuturesUnordered { /// Returns an iterator that allows modifying each future in the set. pub fn iter_mut(&mut self) -> IterMut where Fut: Unpin { - IterMut(PinMut::new(self).iter_pin_mut()) + IterMut(Pin::new(self).iter_pin_mut()) } /// Returns an iterator that allows modifying each future in the set. #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 - pub fn iter_pin_mut<'a>(self: PinMut<'a, Self>) -> IterPinMut<'a, Fut> { + pub fn iter_pin_mut<'a>(self: Pin<&'a mut Self>) -> IterPinMut<'a, Fut> { IterPinMut { task: self.head_all, len: self.len, @@ -254,7 +254,7 @@ impl FuturesUnordered { impl Stream for FuturesUnordered { type Item = Fut::Output; - fn poll_next(mut self: PinMut, cx: &mut core_task::Context) + fn poll_next(mut self: Pin<&mut Self>, cx: &mut core_task::Context) -> Poll> { // Ensure `parent` is correctly set. @@ -370,7 +370,7 @@ impl Stream for FuturesUnordered { let mut cx = cx.with_waker(&*local_waker); // Safety: We won't move the future ever again - let future = unsafe { PinMut::new_unchecked(future) }; + let future = unsafe { Pin::new_unchecked(future) }; future.poll(&mut cx) }; diff --git a/futures-util/src/stream/inspect.rs b/futures-util/src/stream/inspect.rs index aee6bd00b7..ab6649efe9 100644 --- a/futures-util/src/stream/inspect.rs +++ b/futures-util/src/stream/inspect.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -58,7 +58,7 @@ impl Stream for Inspect type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { let item = ready!(self.stream().poll_next(cx)); diff --git a/futures-util/src/stream/into_future.rs b/futures-util/src/stream/into_future.rs index a864fc3ab8..4c75773b7c 100644 --- a/futures-util/src/stream/into_future.rs +++ b/futures-util/src/stream/into_future.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -62,12 +62,12 @@ impl Future for StreamFuture { type Output = (Option, St); fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll { let item = { let s = self.stream.as_mut().expect("polling StreamFuture twice"); - ready!(PinMut::new(s).poll_next(cx)) + ready!(Pin::new(s).poll_next(cx)) }; let stream = self.stream.take().unwrap(); Poll::Ready((item, stream)) diff --git a/futures-util/src/stream/iter.rs b/futures-util/src/stream/iter.rs index 3fe81d59e6..d0d101eb9e 100644 --- a/futures-util/src/stream/iter.rs +++ b/futures-util/src/stream/iter.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -40,7 +40,7 @@ impl Stream for Iter { type Item = I::Item; - fn poll_next(mut self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(self.iter.next()) } } diff --git a/futures-util/src/stream/map.rs b/futures-util/src/stream/map.rs index 9fd2ef2406..186934a667 100644 --- a/futures-util/src/stream/map.rs +++ b/futures-util/src/stream/map.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -59,7 +59,7 @@ impl Stream for Map type Item = T; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { let option = ready!(self.stream().poll_next(cx)); diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index e524fc0503..6b346a892b 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -4,7 +4,7 @@ //! including the `StreamExt` trait which adds methods to `Stream` types. use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use either::Either; use futures_core::future::Future; use futures_core::stream::Stream; @@ -95,7 +95,6 @@ pub use self::zip::Zip; if_std! { use std; use std::iter::Extend; - use std::pin::PinBox; mod buffer_unordered; pub use self::buffer_unordered::BufferUnordered; @@ -779,10 +778,10 @@ pub trait StreamExt: Stream { /// Wrap the stream in a Box, pinning it. #[cfg(feature = "std")] - fn boxed(self) -> PinBox + fn boxed(self) -> Pin> where Self: Sized { - PinBox::new(self) + Box::pinned(self) } /// An adaptor for creating a buffered list of pending futures. @@ -1037,6 +1036,6 @@ pub trait StreamExt: Stream { ) -> Poll> where Self: Unpin + Sized { - PinMut::new(self).poll_next(cx) + Pin::new(self).poll_next(cx) } } diff --git a/futures-util/src/stream/next.rs b/futures-util/src/stream/next.rs index 0d9537e8cf..d4dda448bb 100644 --- a/futures-util/src/stream/next.rs +++ b/futures-util/src/stream/next.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -23,9 +23,9 @@ impl Future for Next<'_, St> { type Output = Option; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { - PinMut::new(&mut *self.stream).poll_next(cx) + Pin::new(&mut *self.stream).poll_next(cx) } } diff --git a/futures-util/src/stream/once.rs b/futures-util/src/stream/once.rs index 8139678905..d060991aa8 100644 --- a/futures-util/src/stream/once.rs +++ b/futures-util/src/stream/once.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -39,7 +39,7 @@ impl Stream for Once { type Item = Fut::Output; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { let val = if let Some(f) = self.future().as_pin_mut() { @@ -47,7 +47,7 @@ impl Stream for Once { } else { return Poll::Ready(None) }; - PinMut::set(self.future(), None); + Pin::set(self.future(), None); Poll::Ready(Some(val)) } } diff --git a/futures-util/src/stream/peek.rs b/futures-util/src/stream/peek.rs index 4cc1380ec6..e6dda913a1 100644 --- a/futures-util/src/stream/peek.rs +++ b/futures-util/src/stream/peek.rs @@ -1,6 +1,6 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -35,7 +35,7 @@ impl Peekable { /// This method polls the underlying stream and return either a reference /// to the next item if the stream is ready or passes through any errors. pub fn peek<'a>( - self: &'a mut PinMut, + self: &'a mut Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if self.peeked().is_some() { @@ -55,7 +55,7 @@ impl Stream for Peekable { type Item = S::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { if let Some(item) = self.peeked().take() { diff --git a/futures-util/src/stream/poll_fn.rs b/futures-util/src/stream/poll_fn.rs index e327a3c176..f78ddd2e30 100644 --- a/futures-util/src/stream/poll_fn.rs +++ b/futures-util/src/stream/poll_fn.rs @@ -1,7 +1,7 @@ //! Definition of the `PollFn` combinator use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -48,7 +48,7 @@ where { type Item = T; - fn poll_next(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { (&mut self.f)(cx) } } diff --git a/futures-util/src/stream/repeat.rs b/futures-util/src/stream/repeat.rs index ab8245eab5..6be7c87ab6 100644 --- a/futures-util/src/stream/repeat.rs +++ b/futures-util/src/stream/repeat.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -38,7 +38,7 @@ impl Stream for Repeat { type Item = T; - fn poll_next(self: PinMut, _: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { Poll::Ready(Some(self.item.clone())) } } diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index 566db8ec15..cfc0f9de09 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -1,6 +1,6 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -43,13 +43,13 @@ impl Stream for Select type Item = St1::Item; fn poll_next( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { let Select { flag, stream1, stream2 } = - unsafe { PinMut::get_mut_unchecked(self) }; - let stream1 = unsafe { PinMut::new_unchecked(stream1) }; - let stream2 = unsafe { PinMut::new_unchecked(stream2) }; + unsafe { Pin::get_mut_unchecked(self) }; + let stream1 = unsafe { Pin::new_unchecked(stream1) }; + let stream2 = unsafe { Pin::new_unchecked(stream2) }; if *flag { poll_inner(flag, stream1, stream2, cx) @@ -61,8 +61,8 @@ impl Stream for Select fn poll_inner( flag: &mut bool, - a: PinMut, - b: PinMut, + a: Pin<&mut St1>, + b: Pin<&mut St2>, cx: &mut task::Context ) -> Poll> where St1: Stream, St2: Stream diff --git a/futures-util/src/stream/skip.rs b/futures-util/src/stream/skip.rs index 8ae14036e7..25e7e96f30 100644 --- a/futures-util/src/stream/skip.rs +++ b/futures-util/src/stream/skip.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -55,7 +55,7 @@ impl Stream for Skip { type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { while *self.remaining() > 0 { diff --git a/futures-util/src/stream/skip_while.rs b/futures-util/src/stream/skip_while.rs index 90ee4ece3f..c709df8c98 100644 --- a/futures-util/src/stream/skip_while.rs +++ b/futures-util/src/stream/skip_while.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -74,7 +74,7 @@ impl Stream for SkipWhile type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.done_skipping() { @@ -88,13 +88,13 @@ impl Stream for SkipWhile None => return Poll::Ready(None), }; let fut = (self.f())(&item); - PinMut::set(self.pending_fut(), Some(fut)); + Pin::set(self.pending_fut(), Some(fut)); *self.pending_item() = Some(item); } let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); let item = self.pending_item().take().unwrap(); - PinMut::set(self.pending_fut(), None); + Pin::set(self.pending_fut(), None); if !skipped { *self.done_skipping() = true; diff --git a/futures-util/src/stream/split.rs b/futures-util/src/stream/split.rs index 10d71fc477..40b0b9420e 100644 --- a/futures-util/src/stream/split.rs +++ b/futures-util/src/stream/split.rs @@ -5,7 +5,7 @@ use std::any::Any; use std::error::Error; use std::fmt; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use crate::lock::BiLock; @@ -28,7 +28,7 @@ impl SplitStream { impl Stream for SplitStream { type Item = S::Item; - fn poll_next(self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { match self.0.poll_lock(cx) { Poll::Ready(mut inner) => inner.as_pin_mut().poll_next(cx), Poll::Pending => Poll::Pending, @@ -68,21 +68,21 @@ impl Sink for SplitSink { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { loop { if self.slot.is_none() { return Poll::Ready(Ok(())); } - try_ready!(self.reborrow().poll_flush(cx)); + try_ready!(self.as_mut().poll_flush(cx)); } } - fn start_send(mut self: PinMut, item: S::SinkItem) -> Result<(), S::SinkError> { + fn start_send(mut self: Pin<&mut Self>, item: S::SinkItem) -> Result<(), S::SinkError> { self.slot = Some(item); Ok(()) } - fn poll_flush(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { let this = &mut *self; match this.lock.poll_lock(cx) { Poll::Ready(mut inner) => { @@ -98,7 +98,7 @@ impl Sink for SplitSink { } } - fn poll_close(mut self: PinMut, cx: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { let this = &mut *self; match this.lock.poll_lock(cx) { Poll::Ready(mut inner) => { diff --git a/futures-util/src/stream/take.rs b/futures-util/src/stream/take.rs index d0e46ea1af..a8275de5b1 100644 --- a/futures-util/src/stream/take.rs +++ b/futures-util/src/stream/take.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -57,7 +57,7 @@ impl Stream for Take type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { if *self.remaining() == 0 { diff --git a/futures-util/src/stream/take_while.rs b/futures-util/src/stream/take_while.rs index a7939ce652..b3518ab85e 100644 --- a/futures-util/src/stream/take_while.rs +++ b/futures-util/src/stream/take_while.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -74,7 +74,7 @@ impl Stream for TakeWhile type Item = St::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.done_taking() { @@ -87,12 +87,12 @@ impl Stream for TakeWhile None => return Poll::Ready(None), }; let fut = (self.f())(&item); - PinMut::set(self.pending_fut(), Some(fut)); + Pin::set(self.pending_fut(), Some(fut)); *self.pending_item() = Some(item); } let take = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); - PinMut::set(self.pending_fut(), None); + Pin::set(self.pending_fut(), None); let item = self.pending_item().take().unwrap(); if take { diff --git a/futures-util/src/stream/then.rs b/futures-util/src/stream/then.rs index f9438cea5c..e71b095464 100644 --- a/futures-util/src/stream/then.rs +++ b/futures-util/src/stream/then.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -44,7 +44,7 @@ impl Stream for Then type Item = Fut::Output; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { if self.future().as_pin_mut().is_none() { @@ -53,11 +53,11 @@ impl Stream for Then Some(e) => e, }; let fut = (self.f())(item); - PinMut::set(self.future(), Some(fut)); + Pin::set(self.future(), Some(fut)); } let e = ready!(self.future().as_pin_mut().unwrap().poll(cx)); - PinMut::set(self.future(), None); + Pin::set(self.future(), None); Poll::Ready(Some(e)) } } diff --git a/futures-util/src/stream/unfold.rs b/futures-util/src/stream/unfold.rs index 6e32a94164..437f3bad34 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; @@ -85,16 +85,16 @@ impl Stream for Unfold type Item = It; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { if let Some(state) = self.state().take() { let fut = (self.f())(state); - PinMut::set(self.fut(), Some(fut)); + Pin::set(self.fut(), Some(fut)); } let step = ready!(self.fut().as_pin_mut().unwrap().poll(cx)); - PinMut::set(self.fut(), None); + Pin::set(self.fut(), None); if let Some((item, next_state)) = step { *self.state() = Some(next_state); diff --git a/futures-util/src/stream/zip.rs b/futures-util/src/stream/zip.rs index 42886c5a5d..0b195204c5 100644 --- a/futures-util/src/stream/zip.rs +++ b/futures-util/src/stream/zip.rs @@ -1,6 +1,6 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -43,7 +43,7 @@ impl Stream for Zip type Item = (St1::Item, St2::Item); fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll> { if self.queued1().is_none() { diff --git a/futures-util/src/task/atomic_waker.rs b/futures-util/src/task/atomic_waker.rs index 6767ce0b19..af7cb58b1b 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-util/src/task/atomic_waker.rs @@ -174,7 +174,7 @@ impl AtomicWaker { /// use futures::task::{self, Poll, AtomicWaker}; /// use std::sync::atomic::AtomicBool; /// use std::sync::atomic::Ordering::SeqCst; - /// use std::pin::PinMut; + /// use std::pin::Pin; /// /// struct Flag { /// waker: AtomicWaker, @@ -184,7 +184,7 @@ impl AtomicWaker { /// impl Future for Flag { /// type Output = (); /// - /// fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll<()> { + /// fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { /// // Register **before** checking `set` to avoid a race condition /// // that would result in lost notifications. /// self.waker.register(cx.waker()); diff --git a/futures-util/src/task/spawn/spawn_with_handle.rs b/futures-util/src/task/spawn/spawn_with_handle.rs index 99a4df77f1..716fb4b867 100644 --- a/futures-util/src/task/spawn/spawn_with_handle.rs +++ b/futures-util/src/task/spawn/spawn_with_handle.rs @@ -5,7 +5,7 @@ use futures_core::future::Future; use futures_core::task::{self, Poll, Spawn, SpawnObjError}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use std::panic::{self, AssertUnwindSafe}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; @@ -33,7 +33,7 @@ impl JoinHandle { impl Future for JoinHandle { type Output = T; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { match self.rx.poll_unpin(cx) { Poll::Ready(Ok(Ok(output))) => Poll::Ready(output), Poll::Ready(Ok(Err(e))) => panic::resume_unwind(e), @@ -60,7 +60,7 @@ impl Wrapped { impl Future for Wrapped { type Output = (); - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { if let Poll::Ready(_) = self.tx().as_mut().unwrap().poll_cancel(cx) { if !self.keep_running().load(Ordering::SeqCst) { // Cancelled, bail out diff --git a/futures-util/src/try_future/and_then.rs b/futures-util/src/try_future/and_then.rs index 49666791d2..e766620f87 100644 --- a/futures-util/src/try_future/and_then.rs +++ b/futures-util/src/try_future/and_then.rs @@ -1,5 +1,5 @@ use super::{TryChain, TryChainAction}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -32,7 +32,7 @@ impl Future for AndThen { type Output = Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.try_chain().poll(cx, |result, async_op| { match result { Ok(ok) => TryChainAction::Future(async_op(ok)), diff --git a/futures-util/src/try_future/err_into.rs b/futures-util/src/try_future/err_into.rs index 7dcdd2c244..839134bc71 100644 --- a/futures-util/src/try_future/err_into.rs +++ b/futures-util/src/try_future/err_into.rs @@ -1,5 +1,5 @@ use core::marker::{PhantomData, Unpin}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -32,7 +32,7 @@ impl Future for ErrInto type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { self.future().try_poll(cx) diff --git a/futures-util/src/try_future/flatten_sink.rs b/futures-util/src/try_future/flatten_sink.rs index 2f448845ce..954875a368 100644 --- a/futures-util/src/try_future/flatten_sink.rs +++ b/futures-util/src/try_future/flatten_sink.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::TryFuture; use futures_core::task::{self, Poll}; use futures_sink::Sink; @@ -30,12 +30,12 @@ where #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 fn project_pin<'a>( - self: PinMut<'a, Self> - ) -> State, PinMut<'a, Si>> { + self: Pin<&'a mut Self> + ) -> State, Pin<&'a mut Si>> { unsafe { - match &mut PinMut::get_mut_unchecked(self).0 { - Waiting(f) => Waiting(PinMut::new_unchecked(f)), - Ready(s) => Ready(PinMut::new_unchecked(s)), + match &mut Pin::get_mut_unchecked(self).0 { + Waiting(f) => Waiting(Pin::new_unchecked(f)), + Ready(s) => Ready(Pin::new_unchecked(s)), Closed => Closed, } } @@ -51,15 +51,15 @@ where type SinkError = Si::SinkError; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - let resolved_stream = match self.reborrow().project_pin() { + let resolved_stream = match self.as_mut().project_pin() { Ready(s) => return s.poll_ready(cx), Waiting(f) => try_ready!(f.try_poll(cx)), Closed => panic!("poll_ready called after eof"), }; - PinMut::set(self.reborrow(), FlattenSink(Ready(resolved_stream))); + Pin::set(self.as_mut(), FlattenSink(Ready(resolved_stream))); if let Ready(resolved_stream) = self.project_pin() { resolved_stream.poll_ready(cx) } else { @@ -68,7 +68,7 @@ where } fn start_send( - self: PinMut, + self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { match self.project_pin() { @@ -79,7 +79,7 @@ where } fn poll_flush( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { match self.project_pin() { @@ -91,15 +91,15 @@ where } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { - let res = match self.reborrow().project_pin() { + let res = match self.as_mut().project_pin() { Ready(s) => s.poll_close(cx), Waiting(_) | Closed => Poll::Ready(Ok(())), }; if res.is_ready() { - PinMut::set(self, FlattenSink(Closed)); + Pin::set(self, FlattenSink(Closed)); } res } diff --git a/futures-util/src/try_future/into_future.rs b/futures-util/src/try_future/into_future.rs index 313e84e89b..6f2c202ded 100644 --- a/futures-util/src/try_future/into_future.rs +++ b/futures-util/src/try_future/into_future.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -24,7 +24,7 @@ impl Future for IntoFuture { #[inline] fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { self.future().try_poll(cx) diff --git a/futures-util/src/try_future/map_err.rs b/futures-util/src/try_future/map_err.rs index c1bc17d7df..fc7395f6d7 100644 --- a/futures-util/src/try_future/map_err.rs +++ b/futures-util/src/try_future/map_err.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -31,7 +31,7 @@ impl Future for MapErr type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { match self.future().try_poll(cx) { diff --git a/futures-util/src/try_future/map_ok.rs b/futures-util/src/try_future/map_ok.rs index 20e6122455..fd6382373f 100644 --- a/futures-util/src/try_future/map_ok.rs +++ b/futures-util/src/try_future/map_ok.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -31,7 +31,7 @@ impl Future for MapOk type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { match self.future().try_poll(cx) { diff --git a/futures-util/src/try_future/or_else.rs b/futures-util/src/try_future/or_else.rs index 6c7e4b6402..18d64c0145 100644 --- a/futures-util/src/try_future/or_else.rs +++ b/futures-util/src/try_future/or_else.rs @@ -1,5 +1,5 @@ use super::{TryChain, TryChainAction}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -33,7 +33,7 @@ impl Future for OrElse type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { self.try_chain().poll(cx, |result, async_op| { diff --git a/futures-util/src/try_future/try_chain.rs b/futures-util/src/try_future/try_chain.rs index 88b1dedc8d..f9e9ebe52a 100644 --- a/futures-util/src/try_future/try_chain.rs +++ b/futures-util/src/try_future/try_chain.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::TryFuture; use futures_core::task::{self, Poll}; @@ -26,7 +26,7 @@ impl TryChain } pub(crate) fn poll( - self: PinMut, + self: Pin<&mut Self>, cx: &mut task::Context, f: F, ) -> Poll> @@ -35,20 +35,20 @@ impl TryChain let mut f = Some(f); // Safe to call `get_mut_unchecked` because we won't move the futures. - let this = unsafe { PinMut::get_mut_unchecked(self) }; + let this = unsafe { Pin::get_mut_unchecked(self) }; loop { let (output, data) = match this { TryChain::First(fut1, data) => { // Poll the first future - match unsafe { PinMut::new_unchecked(fut1) }.try_poll(cx) { + match unsafe { Pin::new_unchecked(fut1) }.try_poll(cx) { Poll::Pending => return Poll::Pending, Poll::Ready(output) => (output, data.take().unwrap()), } } TryChain::Second(fut2) => { // Poll the second future - return unsafe { PinMut::new_unchecked(fut2) }.try_poll(cx) + return unsafe { Pin::new_unchecked(fut2) }.try_poll(cx) } TryChain::Empty => { panic!("future must not be polled after it returned `Poll::Ready`"); diff --git a/futures-util/src/try_future/try_join.rs b/futures-util/src/try_future/try_join.rs index 88ea2b9624..7f4e0007d3 100644 --- a/futures-util/src/try_future/try_join.rs +++ b/futures-util/src/try_future/try_join.rs @@ -3,7 +3,7 @@ use crate::future::{MaybeDone, maybe_done}; use crate::try_future::{TryFutureExt, IntoFuture}; use core::fmt; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -70,7 +70,7 @@ macro_rules! generate { #[allow(clippy::useless_let_if_seq)] fn poll( - mut self: PinMut, cx: &mut task::Context + mut self: Pin<&mut Self>, cx: &mut task::Context ) -> Poll { let mut all_done = true; if self.Fut1().poll(cx).is_pending() { diff --git a/futures-util/src/try_future/unwrap_or_else.rs b/futures-util/src/try_future/unwrap_or_else.rs index ed8dde9ff1..ed212be9ec 100644 --- a/futures-util/src/try_future/unwrap_or_else.rs +++ b/futures-util/src/try_future/unwrap_or_else.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -32,7 +32,7 @@ impl Future for UnwrapOrElse type Output = Fut::Ok; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { match self.future().try_poll(cx) { diff --git a/futures-util/src/try_stream/err_into.rs b/futures-util/src/try_stream/err_into.rs index 0f338fcc23..aef01ab26b 100644 --- a/futures-util/src/try_stream/err_into.rs +++ b/futures-util/src/try_stream/err_into.rs @@ -1,5 +1,5 @@ use core::marker::{PhantomData, Unpin}; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -30,7 +30,7 @@ where type Item = Result; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.stream().try_poll_next(cx) diff --git a/futures-util/src/try_stream/into_stream.rs b/futures-util/src/try_stream/into_stream.rs index 57e3d0b7f4..c421eecb61 100644 --- a/futures-util/src/try_stream/into_stream.rs +++ b/futures-util/src/try_stream/into_stream.rs @@ -1,4 +1,4 @@ -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; use pin_utils::unsafe_pinned; @@ -41,7 +41,7 @@ impl Stream for IntoStream { #[inline] fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.stream().try_poll_next(cx) diff --git a/futures-util/src/try_stream/map_err.rs b/futures-util/src/try_stream/map_err.rs index f6f735d508..3fb318575d 100644 --- a/futures-util/src/try_stream/map_err.rs +++ b/futures-util/src/try_stream/map_err.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -33,7 +33,7 @@ where #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { match self.stream().try_poll_next(cx) { diff --git a/futures-util/src/try_stream/map_ok.rs b/futures-util/src/try_stream/map_ok.rs index cf8043b91e..4e6a39e9c6 100644 --- a/futures-util/src/try_stream/map_ok.rs +++ b/futures-util/src/try_stream/map_ok.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -33,7 +33,7 @@ where #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { match self.stream().try_poll_next(cx) { diff --git a/futures-util/src/try_stream/try_buffer_unordered.rs b/futures-util/src/try_stream/try_buffer_unordered.rs index 4128e7cd3a..861734ca40 100644 --- a/futures-util/src/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/try_stream/try_buffer_unordered.rs @@ -6,7 +6,7 @@ use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; /// A stream returned by the /// [`try_buffer_unordered`](super::TryStreamExt::try_buffer_unordered) method @@ -70,7 +70,7 @@ impl Stream for TryBufferUnordered type Item = Result<::Ok, St::Error>; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { // First up, try to spawn off as many futures as possible by filling up @@ -84,7 +84,7 @@ impl Stream for TryBufferUnordered } // Attempt to pull the next value from the in_progress_queue - match PinMut::new(self.in_progress_queue()).poll_next(cx) { + match Pin::new(self.in_progress_queue()).poll_next(cx) { x @ Poll::Pending | x @ Poll::Ready(Some(_)) => return x, Poll::Ready(None) => {} } diff --git a/futures-util/src/try_stream/try_collect.rs b/futures-util/src/try_stream/try_collect.rs index eb7cdf575f..3fc35aced3 100644 --- a/futures-util/src/try_stream/try_collect.rs +++ b/futures-util/src/try_stream/try_collect.rs @@ -4,7 +4,7 @@ use futures_core::task::{self, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; -use std::pin::PinMut; +use std::pin::Pin; use std::prelude::v1::*; /// A future which attempts to collect all of the values of a stream. @@ -28,7 +28,7 @@ impl TryCollect { } } - fn finish(mut self: PinMut) -> C { + fn finish(mut self: Pin<&mut Self>) -> C { mem::replace(self.items(), Default::default()) } } @@ -41,7 +41,7 @@ impl Future for TryCollect type Output = Result; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { loop { diff --git a/futures-util/src/try_stream/try_filter_map.rs b/futures-util/src/try_stream/try_filter_map.rs index 534a09e6dc..f981634733 100644 --- a/futures-util/src/try_stream/try_filter_map.rs +++ b/futures-util/src/try_stream/try_filter_map.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{TryFuture}; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; @@ -63,7 +63,7 @@ impl Stream for TryFilterMap type Item = Result; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll>> { loop { @@ -74,11 +74,11 @@ impl Stream for TryFilterMap None => return Poll::Ready(None), }; let fut = (self.f())(item); - PinMut::set(self.pending(), Some(fut)); + Pin::set(self.pending(), Some(fut)); } let result = ready!(self.pending().as_pin_mut().unwrap().try_poll(cx)); - PinMut::set(self.pending(), None); + Pin::set(self.pending(), None); match result { Ok(Some(x)) => return Poll::Ready(Some(Ok(x))), Err(e) => return Poll::Ready(Some(Err(e))), diff --git a/futures-util/src/try_stream/try_fold.rs b/futures-util/src/try_stream/try_fold.rs index 6da4a4563b..3014d775be 100644 --- a/futures-util/src/try_stream/try_fold.rs +++ b/futures-util/src/try_stream/try_fold.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::stream::TryStream; use futures_core::task::{self, Poll}; @@ -44,13 +44,13 @@ impl Future for TryFold { type Output = Result; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { loop { // we're currently processing a future to produce a new accum value if self.accum().is_none() { let accum = ready!(self.future().as_pin_mut().unwrap().try_poll(cx)?); *self.accum() = Some(accum); - PinMut::set(self.future(), None); + Pin::set(self.future(), None); } let item = ready!(self.stream().try_poll_next(cx)?); @@ -59,7 +59,7 @@ impl Future for TryFold if let Some(e) = item { let future = (self.f())(accum, e); - PinMut::set(self.future(), Some(future)); + Pin::set(self.future(), Some(future)); } else { return Poll::Ready(Ok(accum)) } diff --git a/futures-util/src/try_stream/try_for_each.rs b/futures-util/src/try_stream/try_for_each.rs index 63f54a1b84..d24db4d434 100644 --- a/futures-util/src/try_stream/try_for_each.rs +++ b/futures-util/src/try_stream/try_for_each.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::stream::TryStream; use futures_core::task::{self, Poll}; @@ -44,17 +44,17 @@ impl Future for TryForEach { type Output = Result<(), St::Error>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { loop { if let Some(future) = self.future().as_pin_mut() { try_ready!(future.try_poll(cx)); } - PinMut::set(self.future(), None); + Pin::set(self.future(), None); match ready!(self.stream().try_poll_next(cx)) { Some(Ok(e)) => { let future = (self.f())(e); - PinMut::set(self.future(), Some(future)); + Pin::set(self.future(), Some(future)); } Some(Err(e)) => return Poll::Ready(Err(e)), None => return Poll::Ready(Ok(())), diff --git a/futures-util/src/try_stream/try_for_each_concurrent.rs b/futures-util/src/try_stream/try_for_each_concurrent.rs index 229c4c97ba..ab7d631713 100644 --- a/futures-util/src/try_stream/try_for_each_concurrent.rs +++ b/futures-util/src/try_stream/try_for_each_concurrent.rs @@ -1,6 +1,6 @@ use crate::stream::{FuturesUnordered, StreamExt}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use core::num::NonZeroUsize; use futures_core::future::Future; use futures_core::stream::TryStream; @@ -55,7 +55,7 @@ impl Future for TryForEachConcurrent { type Output = Result<(), St::Error>; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { loop { let mut made_progress_this_iter = false; @@ -80,7 +80,7 @@ impl Future for TryForEachConcurrent None }; if stream_completed { - PinMut::set(self.stream(), None); + Pin::set(self.stream(), None); } if let Some(elem) = elem { let next_future = (self.f())(elem); diff --git a/futures-util/src/try_stream/try_next.rs b/futures-util/src/try_stream/try_next.rs index 0a1c978e67..46ca2897c8 100644 --- a/futures-util/src/try_stream/try_next.rs +++ b/futures-util/src/try_stream/try_next.rs @@ -2,7 +2,7 @@ use futures_core::future::Future; use futures_core::stream::TryStream; use futures_core::task::{self, Poll}; use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; /// A future which attempts to collect all of the values of a stream. /// @@ -25,10 +25,10 @@ impl Future for TryNext<'_, St> { type Output = Result, St::Error>; fn poll( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll { - match PinMut::new(&mut *self.stream).try_poll_next(cx) { + match Pin::new(&mut *self.stream).try_poll_next(cx) { Poll::Ready(Some(Ok(x))) => Poll::Ready(Ok(Some(x))), Poll::Ready(Some(Err(e))) => Poll::Ready(Err(e)), Poll::Ready(None) => Poll::Ready(Ok(None)), diff --git a/futures-util/src/try_stream/try_skip_while.rs b/futures-util/src/try_stream/try_skip_while.rs index 307808940b..56a4b38e8f 100644 --- a/futures-util/src/try_stream/try_skip_while.rs +++ b/futures-util/src/try_stream/try_skip_while.rs @@ -1,5 +1,5 @@ use core::marker::Unpin; -use core::pin::PinMut; +use core::pin::Pin; use futures_core::future::TryFuture; use futures_core::stream::{Stream, TryStream}; use futures_core::task::{self, Poll}; @@ -76,7 +76,7 @@ impl Stream for TrySkipWhile type Item = Result; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { if *self.done_skipping() { @@ -90,13 +90,13 @@ impl Stream for TrySkipWhile None => return Poll::Ready(None), }; let fut = (self.f())(&item); - PinMut::set(self.pending_fut(), Some(fut)); + Pin::set(self.pending_fut(), Some(fut)); *self.pending_item() = Some(item); } let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().try_poll(cx)?); let item = self.pending_item().take().unwrap(); - PinMut::set(self.pending_fut(), None); + Pin::set(self.pending_fut(), None); if !skipped { *self.done_skipping() = true; diff --git a/futures/tests/eager_drop.rs b/futures/tests/eager_drop.rs index 8ee5473038..887f420840 100644 --- a/futures/tests/eager_drop.rs +++ b/futures/tests/eager_drop.rs @@ -5,7 +5,7 @@ use futures::future::{self, Future, FutureExt, TryFutureExt}; use futures::task::{self, Poll}; use futures_test::future::FutureTestExt; use pin_utils::unsafe_pinned; -use std::pin::PinMut; +use std::pin::Pin; use std::sync::mpsc; #[test] @@ -56,7 +56,7 @@ impl FutureData { impl Future for FutureData { type Output = F::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { self.future().poll(cx) } } diff --git a/futures/tests/split.rs b/futures/tests/split.rs index 7f4c0f4a72..b41412b37b 100644 --- a/futures/tests/split.rs +++ b/futures/tests/split.rs @@ -5,7 +5,7 @@ use futures::sink::{Sink, SinkExt}; use futures::stream::{self, Stream, StreamExt}; use futures::task::{self, Poll}; use pin_utils::unsafe_pinned; -use std::pin::PinMut; +use std::pin::Pin; struct Join { stream: T, @@ -21,7 +21,7 @@ impl Stream for Join { type Item = T::Item; fn poll_next( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.stream().poll_next(cx) @@ -33,28 +33,28 @@ impl Sink for Join { type SinkError = U::SinkError; fn poll_ready( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_ready(cx) } fn start_send( - mut self: PinMut, + mut self: Pin<&mut Self>, item: Self::SinkItem, ) -> Result<(), Self::SinkError> { self.sink().start_send(item) } fn poll_flush( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_flush(cx) } fn poll_close( - mut self: PinMut, + mut self: Pin<&mut Self>, cx: &mut task::Context, ) -> Poll> { self.sink().poll_close(cx)