From 467ec4a02675637df7e107ecf3872ecb49cda230 Mon Sep 17 00:00:00 2001 From: Eunchong Yu Date: Fri, 21 Sep 2018 00:02:41 +0900 Subject: [PATCH 01/14] Follow latest pinning API --- Cargo.toml | 3 + futures-channel/benches/sync_mpsc.rs | 12 +- futures-channel/src/mpsc/mod.rs | 12 +- futures-channel/src/oneshot.rs | 4 +- futures-channel/tests/mpsc.rs | 26 ++-- futures-channel/tests/oneshot.rs | 4 +- futures-core/src/future.rs | 6 +- futures-core/src/stream/mod.rs | 43 ++++--- futures-core/src/stream/stream_obj.rs | 37 +++--- futures-executor/benches/poll.rs | 4 +- futures-executor/benches/thread_notify.rs | 8 +- futures-executor/src/local_pool.rs | 2 +- futures-executor/tests/local_pool.rs | 22 ++-- futures-sink/src/channel_impls.rs | 26 ++-- futures-sink/src/lib.rs | 112 +++++++++--------- futures-test/src/assert.rs | 6 +- futures-test/src/future/assert_unmoved.rs | 4 +- futures-test/src/future/pending_once.rs | 4 +- futures-util/src/async_await/join.rs | 12 +- futures-util/src/async_await/pending.rs | 12 +- futures-util/src/async_await/poll.rs | 6 +- futures-util/src/async_await/select.rs | 2 +- futures-util/src/compat/compat01to03.rs | 10 +- futures-util/src/compat/compat03to01.rs | 6 +- futures-util/src/future/abortable.rs | 4 +- futures-util/src/future/catch_unwind.rs | 4 +- futures-util/src/future/chain.rs | 10 +- futures-util/src/future/empty.rs | 4 +- futures-util/src/future/flatten.rs | 4 +- futures-util/src/future/flatten_stream.rs | 12 +- futures-util/src/future/fuse.rs | 6 +- futures-util/src/future/inspect.rs | 4 +- futures-util/src/future/into_stream.rs | 6 +- futures-util/src/future/join.rs | 4 +- futures-util/src/future/lazy.rs | 6 +- futures-util/src/future/map.rs | 4 +- futures-util/src/future/maybe_done.rs | 26 ++-- futures-util/src/future/mod.rs | 10 +- futures-util/src/future/option.rs | 4 +- futures-util/src/future/poll_fn.rs | 4 +- futures-util/src/future/ready.rs | 4 +- futures-util/src/future/shared.rs | 6 +- futures-util/src/future/then.rs | 4 +- futures-util/src/future/unit_error.rs | 4 +- futures-util/src/future/with_spawner.rs | 8 +- futures-util/src/io/close.rs | 4 +- futures-util/src/io/copy_into.rs | 6 +- futures-util/src/io/flush.rs | 4 +- futures-util/src/io/read.rs | 4 +- futures-util/src/io/read_exact.rs | 4 +- futures-util/src/io/read_to_end.rs | 4 +- futures-util/src/io/split.rs | 4 +- futures-util/src/io/write_all.rs | 4 +- futures-util/src/lib.rs | 8 +- futures-util/src/lock.rs | 8 +- futures-util/src/sink/buffer.rs | 14 +-- futures-util/src/sink/close.rs | 6 +- futures-util/src/sink/drain.rs | 10 +- futures-util/src/sink/err_into.rs | 4 +- futures-util/src/sink/fanout.rs | 10 +- futures-util/src/sink/flush.rs | 6 +- futures-util/src/sink/map_err.rs | 18 +-- futures-util/src/sink/send.rs | 12 +- futures-util/src/sink/send_all.rs | 12 +- futures-util/src/sink/with.rs | 30 ++--- futures-util/src/sink/with_flat_map.rs | 44 +++---- futures-util/src/stream/buffer_unordered.rs | 10 +- futures-util/src/stream/buffered.rs | 10 +- futures-util/src/stream/catch_unwind.rs | 4 +- futures-util/src/stream/chain.rs | 6 +- futures-util/src/stream/chunks.rs | 6 +- futures-util/src/stream/collect.rs | 6 +- futures-util/src/stream/concat.rs | 4 +- .../src/stream/disabled/select_all.rs | 2 +- futures-util/src/stream/empty.rs | 4 +- futures-util/src/stream/filter.rs | 8 +- futures-util/src/stream/filter_map.rs | 8 +- futures-util/src/stream/flatten.rs | 8 +- futures-util/src/stream/fold.rs | 8 +- futures-util/src/stream/for_each.rs | 8 +- .../src/stream/for_each_concurrent.rs | 6 +- futures-util/src/stream/forward.rs | 12 +- futures-util/src/stream/fuse.rs | 8 +- futures-util/src/stream/futures_ordered.rs | 8 +- .../src/stream/futures_unordered/iter.rs | 10 +- .../src/stream/futures_unordered/mod.rs | 10 +- futures-util/src/stream/inspect.rs | 4 +- futures-util/src/stream/into_future.rs | 6 +- futures-util/src/stream/iter.rs | 4 +- futures-util/src/stream/map.rs | 4 +- futures-util/src/stream/mod.rs | 9 +- futures-util/src/stream/next.rs | 6 +- futures-util/src/stream/once.rs | 6 +- futures-util/src/stream/peek.rs | 6 +- futures-util/src/stream/poll_fn.rs | 4 +- futures-util/src/stream/repeat.rs | 4 +- futures-util/src/stream/select.rs | 14 +-- futures-util/src/stream/skip.rs | 4 +- futures-util/src/stream/skip_while.rs | 8 +- futures-util/src/stream/split.rs | 14 +-- futures-util/src/stream/take.rs | 4 +- futures-util/src/stream/take_while.rs | 8 +- futures-util/src/stream/then.rs | 8 +- futures-util/src/stream/unfold.rs | 8 +- futures-util/src/stream/zip.rs | 4 +- futures-util/src/task/atomic_waker.rs | 4 +- .../src/task/spawn/spawn_with_handle.rs | 6 +- futures-util/src/try_future/and_then.rs | 4 +- futures-util/src/try_future/err_into.rs | 4 +- futures-util/src/try_future/flatten_sink.rs | 28 ++--- futures-util/src/try_future/into_future.rs | 4 +- futures-util/src/try_future/map_err.rs | 4 +- futures-util/src/try_future/map_ok.rs | 4 +- futures-util/src/try_future/or_else.rs | 4 +- futures-util/src/try_future/try_chain.rs | 10 +- futures-util/src/try_future/try_join.rs | 4 +- futures-util/src/try_future/unwrap_or_else.rs | 4 +- futures-util/src/try_stream/err_into.rs | 4 +- futures-util/src/try_stream/into_stream.rs | 4 +- futures-util/src/try_stream/map_err.rs | 4 +- futures-util/src/try_stream/map_ok.rs | 4 +- .../src/try_stream/try_buffer_unordered.rs | 6 +- futures-util/src/try_stream/try_collect.rs | 6 +- futures-util/src/try_stream/try_filter_map.rs | 8 +- futures-util/src/try_stream/try_fold.rs | 8 +- futures-util/src/try_stream/try_for_each.rs | 8 +- .../src/try_stream/try_for_each_concurrent.rs | 6 +- futures-util/src/try_stream/try_next.rs | 6 +- futures-util/src/try_stream/try_skip_while.rs | 8 +- futures/tests/eager_drop.rs | 4 +- futures/tests/split.rs | 12 +- 131 files changed, 587 insertions(+), 589 deletions(-) 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..9226c865b7 100644 --- a/futures-channel/benches/sync_mpsc.rs +++ b/futures-channel/benches/sync_mpsc.rs @@ -6,7 +6,7 @@ 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; @@ -100,16 +100,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..ba97853faf 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` +// `PinMut>` is never projected to `Pin<&mut T>` impl Unpin for UnboundedReceiver {} /// The error type for [`Sender`s](Sender) used as `Sink`s. @@ -960,7 +960,7 @@ 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..9602731797 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; @@ -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..822fdc775a 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) + self.as_mut().poll_next(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..aac8f82bc6 100644 --- a/futures-executor/benches/poll.rs +++ b/futures-executor/benches/poll.rs @@ -4,7 +4,7 @@ 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; @@ -31,7 +31,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..9b03669d34 100644 --- a/futures-executor/benches/thread_notify.rs +++ b/futures-executor/benches/thread_notify.rs @@ -4,7 +4,7 @@ use futures::executor::block_on; use futures::future::Future; use futures::task::{self, Poll, Waker}; use std::marker::Unpin; -use std::pin::PinMut; +use std::pin::Pin; use test::Bencher; #[bench] @@ -18,7 +18,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 +46,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 +83,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..9762bd3de7 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,7 @@ 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::pinned(lazy(move |_| { tx.send(()).unwrap(); () })).into()).unwrap(); @@ -68,8 +68,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 +93,7 @@ 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::pinned(lazy(move |_| { cnt.set(cnt.get() + 1); () })).into()).unwrap(); @@ -110,7 +110,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 +130,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,12 +157,12 @@ 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 { + spawn.spawn_local_obj(Box::pinned(Spin { state: state, idx: 1, }).into()).unwrap(); 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/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 105c66ce96..98146297ed 100644 --- a/futures-util/src/compat/compat03to01.rs +++ b/futures-util/src/compat/compat03to01.rs @@ -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) } @@ -120,10 +120,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_ref_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..1e90753683 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}; @@ -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..1059528521 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. /// @@ -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 7a3f27e317..cfa547b587 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 fd1f732b40..45824cba7b 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. @@ -29,7 +29,7 @@ impl<'a, R: AsyncRead + ?Sized> ReadExact<'a, R> { 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..f32c62d289 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)] @@ -26,7 +26,7 @@ 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), + 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 0ffbcc4406..2dfa6c2c95 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. /// @@ -29,7 +29,7 @@ impl<'a, W: AsyncWrite + ?Sized> WriteAll<'a, W> { 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..751179eb51 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; @@ -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..457b6d9d37 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; @@ -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) From 57ef65d95c9411325ee1dbca11aa6f8367ec170e Mon Sep 17 00:00:00 2001 From: Eunchong Yu Date: Fri, 21 Sep 2018 03:01:21 +0900 Subject: [PATCH 02/14] Eliminate remaining 'PinMut' --- futures-channel/src/mpsc/mod.rs | 4 ++-- futures-channel/src/oneshot.rs | 2 +- futures-util/src/future/maybe_done.rs | 2 +- futures-util/src/io/close.rs | 2 +- futures-util/src/io/split.rs | 2 +- futures-util/src/lock.rs | 4 ++-- futures-util/src/stream/chain.rs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index ba97853faf..fa98b7f951 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -139,7 +139,7 @@ pub struct Receiver { #[derive(Debug)] pub struct UnboundedReceiver(Receiver); -// `PinMut>` is never projected to `Pin<&mut T>` +// `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,7 +953,7 @@ 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 { diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index 9602731797..452e4b5735 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -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 {} diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index 1e90753683..eb3890bf36 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -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` diff --git a/futures-util/src/io/close.rs b/futures-util/src/io/close.rs index 1059528521..e3126ed40e 100644 --- a/futures-util/src/io/close.rs +++ b/futures-util/src/io/close.rs @@ -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> { diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index f32c62d289..d5676bdc0e 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -25,7 +25,7 @@ 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`. + // 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/lock.rs b/futures-util/src/lock.rs index 751179eb51..dbff4847a0 100644 --- a/futures-util/src/lock.rs +++ b/futures-util/src/lock.rs @@ -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) { diff --git a/futures-util/src/stream/chain.rs b/futures-util/src/stream/chain.rs index 457b6d9d37..ba12a74d93 100644 --- a/futures-util/src/stream/chain.rs +++ b/futures-util/src/stream/chain.rs @@ -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, From ad3c88fa459858d20e0e07d97138640ba928b918 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 24 Sep 2018 15:57:07 -0700 Subject: [PATCH 03/14] Replace all task::Context -> LocalWaker, cx: -> lw: --- futures-channel/benches/sync_mpsc.rs | 6 +-- futures-channel/src/mpsc/mod.rs | 16 +++---- futures-channel/src/oneshot.rs | 8 ++-- futures-channel/tests/oneshot.rs | 2 +- futures-core/src/future.rs | 4 +- futures-core/src/stream/mod.rs | 20 ++++----- futures-core/src/stream/stream_obj.rs | 16 +++---- futures-executor/benches/poll.rs | 2 +- futures-executor/benches/thread_notify.rs | 6 +-- futures-executor/tests/local_pool.rs | 4 +- futures-io/src/lib.rs | 38 ++++++++--------- futures-sink/src/channel_impls.rs | 18 ++++---- futures-sink/src/lib.rs | 42 +++++++++---------- futures-test/src/future/assert_unmoved.rs | 2 +- futures-test/src/future/pending_once.rs | 2 +- futures-util/benches_disabled/bilock.rs | 2 +- futures-util/src/async_await/pending.rs | 2 +- futures-util/src/async_await/poll.rs | 2 +- futures-util/src/compat/compat01to03.rs | 4 +- futures-util/src/future/abortable.rs | 2 +- futures-util/src/future/catch_unwind.rs | 2 +- futures-util/src/future/chain.rs | 2 +- futures-util/src/future/disabled/join_all.rs | 2 +- futures-util/src/future/disabled/select.rs | 2 +- .../src/future/disabled/select_all.rs | 2 +- futures-util/src/future/disabled/select_ok.rs | 2 +- futures-util/src/future/empty.rs | 2 +- futures-util/src/future/flatten.rs | 2 +- futures-util/src/future/flatten_stream.rs | 2 +- futures-util/src/future/fuse.rs | 2 +- futures-util/src/future/inspect.rs | 2 +- futures-util/src/future/into_stream.rs | 2 +- futures-util/src/future/join.rs | 2 +- futures-util/src/future/lazy.rs | 6 +-- futures-util/src/future/map.rs | 2 +- futures-util/src/future/maybe_done.rs | 2 +- futures-util/src/future/mod.rs | 2 +- futures-util/src/future/option.rs | 2 +- futures-util/src/future/poll_fn.rs | 8 ++-- futures-util/src/future/ready.rs | 2 +- futures-util/src/future/shared.rs | 4 +- futures-util/src/future/then.rs | 2 +- futures-util/src/future/unit_error.rs | 2 +- futures-util/src/future/with_spawner.rs | 2 +- futures-util/src/io/allow_std.rs | 8 ++-- futures-util/src/io/close.rs | 2 +- futures-util/src/io/copy_into.rs | 2 +- futures-util/src/io/disabled/lines.rs | 2 +- futures-util/src/io/flush.rs | 2 +- futures-util/src/io/read.rs | 2 +- futures-util/src/io/read_exact.rs | 2 +- futures-util/src/io/read_to_end.rs | 4 +- futures-util/src/io/split.rs | 16 +++---- futures-util/src/io/write_all.rs | 2 +- futures-util/src/lib.rs | 6 +-- futures-util/src/lock.rs | 4 +- futures-util/src/sink/buffer.rs | 10 ++--- futures-util/src/sink/close.rs | 2 +- futures-util/src/sink/drain.rs | 6 +-- futures-util/src/sink/err_into.rs | 2 +- futures-util/src/sink/fanout.rs | 6 +-- futures-util/src/sink/flush.rs | 2 +- futures-util/src/sink/map_err.rs | 8 ++-- futures-util/src/sink/send.rs | 2 +- futures-util/src/sink/send_all.rs | 4 +- futures-util/src/sink/with.rs | 10 ++--- futures-util/src/sink/with_flat_map.rs | 10 ++--- futures-util/src/stream/buffer_unordered.rs | 2 +- futures-util/src/stream/buffered.rs | 2 +- futures-util/src/stream/catch_unwind.rs | 2 +- futures-util/src/stream/chain.rs | 2 +- futures-util/src/stream/chunks.rs | 2 +- futures-util/src/stream/collect.rs | 2 +- futures-util/src/stream/concat.rs | 2 +- .../src/stream/disabled/select_all.rs | 2 +- futures-util/src/stream/empty.rs | 2 +- futures-util/src/stream/filter.rs | 2 +- futures-util/src/stream/filter_map.rs | 2 +- futures-util/src/stream/flatten.rs | 2 +- futures-util/src/stream/fold.rs | 2 +- futures-util/src/stream/for_each.rs | 2 +- .../src/stream/for_each_concurrent.rs | 2 +- futures-util/src/stream/forward.rs | 4 +- futures-util/src/stream/fuse.rs | 2 +- futures-util/src/stream/futures_ordered.rs | 4 +- .../src/stream/futures_unordered/mod.rs | 2 +- futures-util/src/stream/inspect.rs | 2 +- futures-util/src/stream/into_future.rs | 2 +- futures-util/src/stream/iter.rs | 2 +- futures-util/src/stream/map.rs | 2 +- futures-util/src/stream/mod.rs | 2 +- futures-util/src/stream/next.rs | 2 +- futures-util/src/stream/once.rs | 2 +- futures-util/src/stream/peek.rs | 4 +- futures-util/src/stream/poll_fn.rs | 6 +-- futures-util/src/stream/repeat.rs | 2 +- futures-util/src/stream/select.rs | 4 +- futures-util/src/stream/skip.rs | 2 +- futures-util/src/stream/skip_while.rs | 2 +- futures-util/src/stream/split.rs | 8 ++-- futures-util/src/stream/take.rs | 2 +- futures-util/src/stream/take_while.rs | 2 +- futures-util/src/stream/then.rs | 2 +- futures-util/src/stream/unfold.rs | 2 +- futures-util/src/stream/zip.rs | 2 +- futures-util/src/task/atomic_waker.rs | 2 +- .../src/task/spawn/spawn_with_handle.rs | 4 +- futures-util/src/try_future/and_then.rs | 2 +- futures-util/src/try_future/err_into.rs | 2 +- futures-util/src/try_future/flatten_sink.rs | 6 +-- futures-util/src/try_future/into_future.rs | 2 +- futures-util/src/try_future/map_err.rs | 2 +- futures-util/src/try_future/map_ok.rs | 2 +- futures-util/src/try_future/or_else.rs | 2 +- futures-util/src/try_future/try_chain.rs | 2 +- futures-util/src/try_future/try_join.rs | 2 +- futures-util/src/try_future/unwrap_or_else.rs | 2 +- futures-util/src/try_stream/err_into.rs | 2 +- futures-util/src/try_stream/into_stream.rs | 2 +- futures-util/src/try_stream/map_err.rs | 2 +- futures-util/src/try_stream/map_ok.rs | 2 +- .../src/try_stream/try_buffer_unordered.rs | 2 +- futures-util/src/try_stream/try_collect.rs | 2 +- futures-util/src/try_stream/try_filter_map.rs | 2 +- futures-util/src/try_stream/try_fold.rs | 2 +- futures-util/src/try_stream/try_for_each.rs | 2 +- .../src/try_stream/try_for_each_concurrent.rs | 2 +- futures-util/src/try_stream/try_next.rs | 2 +- futures-util/src/try_stream/try_skip_while.rs | 2 +- futures/tests/eager_drop.rs | 2 +- futures/tests/split.rs | 8 ++-- .../tests_disabled/future_flatten_stream.rs | 2 +- futures/tests_disabled/sink.rs | 20 ++++----- futures/tests_disabled/stream.rs | 4 +- 134 files changed, 278 insertions(+), 278 deletions(-) diff --git a/futures-channel/benches/sync_mpsc.rs b/futures-channel/benches/sync_mpsc.rs index 9226c865b7..b17246b144 100644 --- a/futures-channel/benches/sync_mpsc.rs +++ b/futures-channel/benches/sync_mpsc.rs @@ -20,11 +20,11 @@ fn notify_noop() -> LocalWaker { task::local_waker_from_nonlocal(Arc::new(Noop)) } -fn noop_cx(f: impl FnOnce(&mut task::Context)) { +fn noop_cx(f: impl FnOnce(&LocalWaker)) { let pool = LocalPool::new(); let mut spawn = pool.spawner(); let waker = notify_noop(); - let cx = &mut task::Context::new(&waker, &mut spawn); + let cx = &LocalWaker::new(&waker, &mut spawn); f(cx) } @@ -100,7 +100,7 @@ struct TestSender { impl Stream for TestSender { type Item = u32; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let this = &mut *self; diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index fa98b7f951..9f43aea306 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -451,7 +451,7 @@ impl Sender { // Do the send without failing // None means close - fn do_send(&mut self, cx: Option<&mut task::Context>, msg: T) + fn do_send(&mut self, lw: Option<&LocalWaker>, msg: T) -> Result<(), TrySendError> { // Anyone callig do_send *should* make sure there is room first, @@ -616,7 +616,7 @@ impl Sender { } } - fn park(&mut self, cx: Option<&mut task::Context>) { + fn park(&mut self, lw: Option<&LocalWaker>) { // TODO: clean up internal state if the task::current will fail let task = cx.map(|cx| cx.waker().clone()); @@ -651,7 +651,7 @@ impl Sender { /// - `Err(SendError)` if the receiver has been dropped. pub fn poll_ready( &mut self, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { let state = decode_state(self.inner.state.load(SeqCst)); if !state.is_open { @@ -677,7 +677,7 @@ impl Sender { let _ = self.do_send_nb(None); } - fn poll_unparked(&mut self, cx: Option<&mut task::Context>) -> Poll<()> { + fn poll_unparked(&mut self, lw: Option<&LocalWaker>) -> Poll<()> { // First check the `maybe_parked` variable. This avoids acquiring the // lock in most cases if self.maybe_parked { @@ -708,7 +708,7 @@ impl UnboundedSender { /// Check if the channel is ready to receive a message. pub fn poll_ready( &self, - _: &mut task::Context, + _: &LocalWaker, ) -> Poll> { self.0.poll_ready_nb() } @@ -914,7 +914,7 @@ impl Receiver { } // Try to park the receiver task - fn try_park(&self, cx: &mut task::Context) -> TryPark { + fn try_park(&self, lw: &LocalWaker) -> TryPark { let curr = self.inner.state.load(SeqCst); let state = decode_state(curr); @@ -961,7 +961,7 @@ impl Stream for Receiver { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { loop { // Try to read a message off of the message queue. @@ -1031,7 +1031,7 @@ impl Stream for UnboundedReceiver { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { Pin::new(&mut self.0).poll_next(cx) } diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index 452e4b5735..d25ffcb9dc 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -155,7 +155,7 @@ impl Inner { } } - fn poll_cancel(&self, cx: &mut task::Context) -> Poll<()> { + fn poll_cancel(&self, lw: &LocalWaker) -> Poll<()> { // Fast path up first, just read the flag and see if our other half is // gone. This flag is set both in our destructor and the oneshot // destructor, but our destructor hasn't run yet so if it's set then the @@ -250,7 +250,7 @@ impl Inner { } } - fn recv(&self, cx: &mut task::Context) -> Poll> { + fn recv(&self, lw: &LocalWaker) -> Poll> { // Check to see if some data has arrived. If it hasn't then we need to // block our task. // @@ -349,7 +349,7 @@ impl Sender { /// alive and may be able to receive a message if sent. The current task, /// however, is scheduled to receive a notification if the corresponding /// `Receiver` goes away. - pub fn poll_cancel(&mut self, cx: &mut task::Context) -> Poll<()> { + pub fn poll_cancel(&mut self, lw: &LocalWaker) -> Poll<()> { self.inner.poll_cancel(cx) } @@ -420,7 +420,7 @@ impl Future for Receiver { fn poll( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.inner.recv(cx) } diff --git a/futures-channel/tests/oneshot.rs b/futures-channel/tests/oneshot.rs index acf83a9614..9acc8056fb 100644 --- a/futures-channel/tests/oneshot.rs +++ b/futures-channel/tests/oneshot.rs @@ -42,7 +42,7 @@ struct WaitForCancel { impl Future for WaitForCancel { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { self.tx.poll_cancel(cx) } } diff --git a/futures-core/src/future.rs b/futures-core/src/future.rs index fbbf9673b4..bc8fa5f3a3 100644 --- a/futures-core/src/future.rs +++ b/futures-core/src/future.rs @@ -21,7 +21,7 @@ pub trait TryFuture { /// needed. fn try_poll( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll>; } @@ -32,7 +32,7 @@ impl TryFuture for F type Error = E; #[inline] - fn try_poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn try_poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { self.poll(cx) } } diff --git a/futures-core/src/stream/mod.rs b/futures-core/src/stream/mod.rs index 822fdc775a..494b5d2809 100644 --- a/futures-core/src/stream/mod.rs +++ b/futures-core/src/stream/mod.rs @@ -53,7 +53,7 @@ pub trait Stream { /// calls. fn poll_next( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll>; } @@ -62,7 +62,7 @@ impl<'a, S: ?Sized + Stream + Unpin> Stream for &'a mut S { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { S::poll_next(Pin::new(&mut **self), cx) } @@ -73,7 +73,7 @@ impl<'a, S: ?Sized + Stream> Stream for Pin<&'a mut S> { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { S::poll_next((*self).as_mut(), cx) } @@ -86,7 +86,7 @@ impl Stream for Either { type Item = A::Item; - fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { match Pin::get_mut_unchecked(self) { Either::Left(a) => Pin::new_unchecked(a).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: Pin<&mut Self>, cx: &mut task::Context) + fn try_poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll>>; } @@ -120,7 +120,7 @@ impl TryStream for S type Ok = T; type Error = E; - fn try_poll_next(self: Pin<&mut Self>, cx: &mut task::Context) + fn try_poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll>> { self.poll_next(cx) @@ -135,7 +135,7 @@ if_std! { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { Pin::new(&mut **self).poll_next(cx) } @@ -146,7 +146,7 @@ if_std! { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.as_mut().poll_next(cx) } @@ -157,7 +157,7 @@ if_std! { fn poll_next( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }.poll_next(cx) } @@ -168,7 +168,7 @@ if_std! { fn poll_next( mut self: Pin<&mut Self>, - _cx: &mut task::Context, + _lw: &LocalWaker, ) -> 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 d821a72aa2..ab146e980b 100644 --- a/futures-core/src/stream/stream_obj.rs +++ b/futures-core/src/stream/stream_obj.rs @@ -17,7 +17,7 @@ use core::pin::Pin; /// information #44874) pub struct LocalStreamObj<'a, T> { ptr: *mut (), - poll_next_fn: unsafe fn(*mut (), &mut task::Context) -> Poll>, + poll_next_fn: unsafe fn(*mut (), &LocalWaker) -> Poll>, drop_fn: unsafe fn(*mut ()), _marker: PhantomData<&'a ()>, } @@ -65,7 +65,7 @@ impl<'a, T> Stream for LocalStreamObj<'a, T> { #[inline] fn poll_next( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { unsafe { (self.poll_next_fn)(self.ptr, cx) } } @@ -113,7 +113,7 @@ impl<'a, T> Stream for StreamObj<'a, T> { #[inline] fn poll_next( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }; pinned_field.poll_next(cx) @@ -143,7 +143,7 @@ pub unsafe trait UnsafeStreamObj<'a, T>: 'a { /// `drop`. unsafe fn poll_next( ptr: *mut (), - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll>; /// Drops the stream represented by the given void pointer. @@ -166,7 +166,7 @@ where unsafe fn poll_next( ptr: *mut (), - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) } @@ -184,7 +184,7 @@ where unsafe fn poll_next( ptr: *mut (), - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) } @@ -202,7 +202,7 @@ if_std! { Box::into_raw(self) as *mut () } - unsafe fn poll_next(ptr: *mut (), cx: &mut task::Context) -> Poll> { + unsafe fn poll_next(ptr: *mut (), lw: &LocalWaker) -> Poll> { let ptr = ptr as *mut F; let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); pin.poll_next(cx) @@ -220,7 +220,7 @@ if_std! { 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> { + unsafe fn poll_next(ptr: *mut (), lw: &LocalWaker) -> Poll> { let ptr = ptr as *mut F; let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); pin.poll_next(cx) diff --git a/futures-executor/benches/poll.rs b/futures-executor/benches/poll.rs index aac8f82bc6..21060a4220 100644 --- a/futures-executor/benches/poll.rs +++ b/futures-executor/benches/poll.rs @@ -31,7 +31,7 @@ fn task_init(b: &mut Bencher) { impl Future for MyFuture { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 9b03669d34..95ab1f5b39 100644 --- a/futures-executor/benches/thread_notify.rs +++ b/futures-executor/benches/thread_notify.rs @@ -18,7 +18,7 @@ fn thread_yield_single_thread_one_wait(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { @@ -46,7 +46,7 @@ fn thread_yield_single_thread_many_wait(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { @@ -83,7 +83,7 @@ fn thread_yield_multi_thread(b: &mut Bencher) { impl Future for Yield { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { if self.rem == 0 { Poll::Ready(()) } else { diff --git a/futures-executor/tests/local_pool.rs b/futures-executor/tests/local_pool.rs index 9762bd3de7..2483a523fb 100644 --- a/futures-executor/tests/local_pool.rs +++ b/futures-executor/tests/local_pool.rs @@ -13,7 +13,7 @@ struct Pending(Rc<()>); impl Future for Pending { type Output = (); - fn poll(self: Pin<&mut Self>, _cx: &mut task::Context) -> Poll<()> { + fn poll(self: Pin<&mut Self>, _lw: &LocalWaker) -> Poll<()> { Poll::Pending } } @@ -130,7 +130,7 @@ fn tasks_are_scheduled_fairly() { impl Future for Spin { type Output = (); - fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { let mut state = self.state.borrow_mut(); if self.idx == 0 { diff --git a/futures-io/src/lib.rs b/futures-io/src/lib.rs index 7837bd2aee..a26be38f1f 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -115,7 +115,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) + fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll>; /// Attempt to read from the `AsyncRead` into `vec` using vectored @@ -140,7 +140,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_vectored_read(&mut self, cx: &mut task::Context, vec: &mut [&mut IoVec]) + fn poll_vectored_read(&mut self, lw: &LocalWaker, vec: &mut [&mut IoVec]) -> Poll> { if let Some(ref mut first_iovec) = vec.get_mut(0) { @@ -175,7 +175,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) + fn poll_write(&mut self, lw: &LocalWaker, buf: &[u8]) -> Poll>; /// Attempt to write bytes from `vec` into the object using vectored @@ -201,7 +201,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_vectored_write(&mut self, cx: &mut task::Context, vec: &[&IoVec]) + fn poll_vectored_write(&mut self, lw: &LocalWaker, vec: &[&IoVec]) -> Poll> { if let Some(ref first_iovec) = vec.get(0) { @@ -228,7 +228,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_flush(&mut self, cx: &mut task::Context) -> Poll>; + fn poll_flush(&mut self, lw: &LocalWaker) -> Poll>; /// Attempt to close the object. /// @@ -245,7 +245,7 @@ if_std! { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Async::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_close(&mut self, cx: &mut task::Context) -> Poll>; + fn poll_close(&mut self, lw: &LocalWaker) -> Poll>; } macro_rules! deref_async_read { @@ -254,13 +254,13 @@ if_std! { (**self).initializer() } - fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) + fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll> { (**self).poll_read(cx, buf) } - fn poll_vectored_read(&mut self, cx: &mut task::Context, vec: &mut [&mut IoVec]) + fn poll_vectored_read(&mut self, lw: &LocalWaker, vec: &mut [&mut IoVec]) -> Poll> { (**self).poll_vectored_read(cx, vec) @@ -284,7 +284,7 @@ if_std! { Initializer::nop() } - fn poll_read(&mut self, _: &mut task::Context, buf: &mut [u8]) + fn poll_read(&mut self, _: &LocalWaker, buf: &mut [u8]) -> Poll> { Poll::Ready(StdIo::Read::read(self, buf)) @@ -306,23 +306,23 @@ if_std! { macro_rules! deref_async_write { () => { - fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) + fn poll_write(&mut self, lw: &LocalWaker, buf: &[u8]) -> Poll> { (**self).poll_write(cx, buf) } - fn poll_vectored_write(&mut self, cx: &mut task::Context, vec: &[&IoVec]) + fn poll_vectored_write(&mut self, lw: &LocalWaker, vec: &[&IoVec]) -> Poll> { (**self).poll_vectored_write(cx, vec) } - fn poll_flush(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_flush(&mut self, lw: &LocalWaker) -> Poll> { (**self).poll_flush(cx) } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { (**self).poll_close(cx) } } @@ -338,17 +338,17 @@ if_std! { macro_rules! delegate_async_write_to_stdio { () => { - fn poll_write(&mut self, _: &mut task::Context, buf: &[u8]) + fn poll_write(&mut self, _: &LocalWaker, buf: &[u8]) -> Poll> { Poll::Ready(StdIo::Write::write(self, buf)) } - fn poll_flush(&mut self, _: &mut task::Context) -> Poll> { + fn poll_flush(&mut self, _: &LocalWaker) -> Poll> { Poll::Ready(StdIo::Write::flush(self)) } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { self.poll_flush(cx) } } @@ -357,7 +357,7 @@ if_std! { impl> AsyncWrite for StdIo::Cursor { fn poll_write( &mut self, - _: &mut task::Context, + _: &LocalWaker, buf: &[u8], ) -> Poll> { let position = self.position(); @@ -372,11 +372,11 @@ if_std! { Poll::Ready(result) } - fn poll_flush(&mut self, _: &mut task::Context) -> Poll> { + fn poll_flush(&mut self, _: &LocalWaker) -> Poll> { Poll::Ready(StdIo::Write::flush(&mut self.get_mut().as_mut())) } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { self.poll_flush(cx) } } diff --git a/futures-sink/src/channel_impls.rs b/futures-sink/src/channel_impls.rs index ad977631d8..9515ed5654 100644 --- a/futures-sink/src/channel_impls.rs +++ b/futures-sink/src/channel_impls.rs @@ -7,7 +7,7 @@ impl Sink for Sender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { (*self).poll_ready(cx) } @@ -15,11 +15,11 @@ impl Sink for Sender { (*self).start_send(msg) } - fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } @@ -29,7 +29,7 @@ impl Sink for UnboundedSender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { UnboundedSender::poll_ready(&*self, cx) } @@ -37,11 +37,11 @@ impl Sink for UnboundedSender { UnboundedSender::start_send(&mut *self, msg) } - fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } @@ -51,7 +51,7 @@ impl<'a, T> Sink for &'a UnboundedSender { type SinkItem = T; type SinkError = SendError; - fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { UnboundedSender::poll_ready(*self, cx) } @@ -60,11 +60,11 @@ impl<'a, T> Sink for &'a UnboundedSender { .map_err(|err| err.into_send_error()) } - fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { self.close_channel(); Poll::Ready(Ok(())) } diff --git a/futures-sink/src/lib.rs b/futures-sink/src/lib.rs index 65e9cee4e3..104a7af437 100644 --- a/futures-sink/src/lib.rs +++ b/futures-sink/src/lib.rs @@ -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: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; + fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll>; /// Begin the process of sending a value to the sink. /// Each call to this function must be proceeded by a successful call to @@ -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: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; + fn poll_flush(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll>; /// Flush any remaining output and close this sink, if necessary. /// @@ -114,14 +114,14 @@ 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: Pin<&mut Self>, cx: &mut task::Context) -> Poll>; + fn poll_close(self: Pin<&mut Self>, lw: &LocalWaker) -> 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: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_ready(cx) } @@ -129,11 +129,11 @@ impl<'a, S: ?Sized + Sink + Unpin> Sink for &'a mut S { Pin::new(&mut **self).start_send(item) } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_flush(cx) } - fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_close(cx) } } @@ -142,7 +142,7 @@ impl<'a, S: ?Sized + Sink> Sink for Pin<&'a mut S> { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { S::poll_ready((*self).as_mut(), cx) } @@ -150,11 +150,11 @@ impl<'a, S: ?Sized + Sink> Sink for Pin<&'a mut S> { S::start_send((*self).as_mut(), item) } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { S::poll_flush((*self).as_mut(), cx) } - fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { S::poll_close((*self).as_mut(), cx) } } @@ -171,7 +171,7 @@ if_std! { type SinkItem = T; type SinkError = VecSinkError; - fn poll_ready(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } @@ -181,11 +181,11 @@ if_std! { Ok(()) } - fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } } @@ -194,7 +194,7 @@ if_std! { type SinkItem = T; type SinkError = VecSinkError; - fn poll_ready(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } @@ -204,11 +204,11 @@ if_std! { Ok(()) } - fn poll_flush(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Ok(())) } } @@ -217,7 +217,7 @@ if_std! { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_ready(cx) } @@ -225,11 +225,11 @@ if_std! { Pin::new(&mut **self).start_send(item) } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_flush(cx) } - fn poll_close(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { Pin::new(&mut **self).poll_close(cx) } } @@ -246,7 +246,7 @@ impl Sink for Either type SinkItem = ::SinkItem; type SinkError = ::SinkError; - fn poll_ready(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { match Pin::get_mut_unchecked(self) { Either::Left(x) => Pin::new_unchecked(x).poll_ready(cx), @@ -264,7 +264,7 @@ impl Sink for Either } } - fn poll_flush(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { match Pin::get_mut_unchecked(self) { Either::Left(x) => Pin::new_unchecked(x).poll_flush(cx), @@ -273,7 +273,7 @@ impl Sink for Either } } - fn poll_close(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_close(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { match Pin::get_mut_unchecked(self) { Either::Left(x) => Pin::new_unchecked(x).poll_close(cx), diff --git a/futures-test/src/future/assert_unmoved.rs b/futures-test/src/future/assert_unmoved.rs index 0d117288bc..3804e2fac2 100644 --- a/futures-test/src/future/assert_unmoved.rs +++ b/futures-test/src/future/assert_unmoved.rs @@ -34,7 +34,7 @@ impl Future for AssertUnmoved { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { let cur_this = &*self as *const Self; if self.this_ptr.is_null() { diff --git a/futures-test/src/future/pending_once.rs b/futures-test/src/future/pending_once.rs index b8f0c3684c..810ef925df 100644 --- a/futures-test/src/future/pending_once.rs +++ b/futures-test/src/future/pending_once.rs @@ -33,7 +33,7 @@ impl Future for PendingOnce { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { if *self.polled_before() { self.future().poll(cx) diff --git a/futures-util/benches_disabled/bilock.rs b/futures-util/benches_disabled/bilock.rs index f6963ca49a..ac5f345da3 100644 --- a/futures-util/benches_disabled/bilock.rs +++ b/futures-util/benches_disabled/bilock.rs @@ -45,7 +45,7 @@ impl Stream for LockStream { type Item = BiLockAcquired; type Error = (); - fn poll_next(&mut self, cx: &mut task::Context) -> Poll, Self::Error> { + fn poll_next(&mut self, lw: &LocalWaker) -> Poll, Self::Error> { self.lock.poll(cx).map(|a| match a { Async::Ready(a) => Async::Ready(Some(a)), Async::Pending => Async::Pending, diff --git a/futures-util/src/async_await/pending.rs b/futures-util/src/async_await/pending.rs index 302e7b3213..dc48e3a6eb 100644 --- a/futures-util/src/async_await/pending.rs +++ b/futures-util/src/async_await/pending.rs @@ -30,7 +30,7 @@ pub struct PendingOnce { impl Future for PendingOnce { type Output = (); - fn poll(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, _: &LocalWaker) -> 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 43b0ee16ae..588fc39194 100644 --- a/futures-util/src/async_await/poll.rs +++ b/futures-util/src/async_await/poll.rs @@ -27,7 +27,7 @@ pub struct PollOnce { impl Future for PollOnce { type Output = Poll; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { Poll::Ready(Pin::new(&mut self.future).poll(cx)) } } diff --git a/futures-util/src/compat/compat01to03.rs b/futures-util/src/compat/compat01to03.rs index 61b10f1334..d21a4a9769 100644 --- a/futures-util/src/compat/compat01to03.rs +++ b/futures-util/src/compat/compat01to03.rs @@ -12,7 +12,7 @@ impl Future03 for Compat { fn poll( self: Pin<&mut Self>, - cx: &mut task03::Context, + lw: &mut task03::Context, ) -> task03::Poll { let notify = &WakerToHandle(cx.waker()); @@ -31,7 +31,7 @@ impl Stream03 for Compat { fn poll_next( self: Pin<&mut Self>, - cx: &mut task03::Context, + lw: &mut task03::Context, ) -> task03::Poll> { let notify = &WakerToHandle(cx.waker()); diff --git a/futures-util/src/future/abortable.rs b/futures-util/src/future/abortable.rs index 645e4c58f1..b50c8ba528 100644 --- a/futures-util/src/future/abortable.rs +++ b/futures-util/src/future/abortable.rs @@ -122,7 +122,7 @@ pub struct Aborted; impl Future for Abortable where Fut: Future { type Output = Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 ec76f44a83..c7714c9b66 100644 --- a/futures-util/src/future/catch_unwind.rs +++ b/futures-util/src/future/catch_unwind.rs @@ -28,7 +28,7 @@ impl Future for CatchUnwind { type Output = Result>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 fab30b29f5..66e91e7fb2 100644 --- a/futures-util/src/future/chain.rs +++ b/futures-util/src/future/chain.rs @@ -20,7 +20,7 @@ impl Chain pub(crate) fn poll( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, f: F, ) -> Poll where F: FnOnce(Fut1::Output, Data) -> Fut2, diff --git a/futures-util/src/future/disabled/join_all.rs b/futures-util/src/future/disabled/join_all.rs index d9ae0cd7dc..a59b8377f1 100644 --- a/futures-util/src/future/disabled/join_all.rs +++ b/futures-util/src/future/disabled/join_all.rs @@ -87,7 +87,7 @@ impl Future for JoinAll type Error = F::Error; - fn poll(&mut self, cx: &mut task::Context) -> Poll { + fn poll(&mut self, lw: &LocalWaker) -> Poll { let mut all_done = true; for idx in 0 .. self.elems.len() { diff --git a/futures-util/src/future/disabled/select.rs b/futures-util/src/future/disabled/select.rs index cf994d4ce3..b76c2d2572 100644 --- a/futures-util/src/future/disabled/select.rs +++ b/futures-util/src/future/disabled/select.rs @@ -23,7 +23,7 @@ impl Future for Select where A: Future, B: Future { type Item = Either<(A::Item, B), (B::Item, A)>; type Error = Either<(A::Error, B), (B::Error, A)>; - fn poll(&mut self, cx: &mut task::Context) -> Poll { + fn poll(&mut self, lw: &LocalWaker) -> Poll { let (mut a, mut b) = self.inner.take().expect("cannot poll Select twice"); match a.poll(cx) { Err(e) => Err(Either::Left((e, b))), diff --git a/futures-util/src/future/disabled/select_all.rs b/futures-util/src/future/disabled/select_all.rs index 38c2594a32..d01fc49480 100644 --- a/futures-util/src/future/disabled/select_all.rs +++ b/futures-util/src/future/disabled/select_all.rs @@ -49,7 +49,7 @@ impl Future for SelectAll type Item = (A::Item, usize, Vec); type Error = (A::Error, usize, Vec); - fn poll(&mut self, cx: &mut task::Context) -> Poll { + fn poll(&mut self, lw: &LocalWaker) -> Poll { let item = self.inner.iter_mut().enumerate().filter_map(|(i, f)| { match f.poll(cx) { Ok(Async::Pending) => None, diff --git a/futures-util/src/future/disabled/select_ok.rs b/futures-util/src/future/disabled/select_ok.rs index 24a7200f96..29102036d2 100644 --- a/futures-util/src/future/disabled/select_ok.rs +++ b/futures-util/src/future/disabled/select_ok.rs @@ -45,7 +45,7 @@ impl Future for SelectOk where A: Future { type Item = (A::Item, Vec); type Error = A::Error; - fn poll(&mut self, cx: &mut task::Context) -> Poll { + fn poll(&mut self, lw: &LocalWaker) -> Poll { // loop until we've either exhausted all errors, a success was hit, or nothing is ready loop { let item = self.inner.iter_mut().enumerate().filter_map(|(i, f)| { diff --git a/futures-util/src/future/empty.rs b/futures-util/src/future/empty.rs index 158af17a4a..f0237968c6 100644 --- a/futures-util/src/future/empty.rs +++ b/futures-util/src/future/empty.rs @@ -36,7 +36,7 @@ pub fn empty() -> Empty { impl Future for Empty { type Output = T; - fn poll(self: Pin<&mut Self>, _: &mut task::Context) -> Poll { + fn poll(self: Pin<&mut Self>, _: &LocalWaker) -> Poll { Poll::Pending } } diff --git a/futures-util/src/future/flatten.rs b/futures-util/src/future/flatten.rs index 7bb80496db..5e468def80 100644 --- a/futures-util/src/future/flatten.rs +++ b/futures-util/src/future/flatten.rs @@ -48,7 +48,7 @@ impl Future for Flatten { type Output = ::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 6c4a4dfdf4..b0c1063788 100644 --- a/futures-util/src/future/flatten_stream.rs +++ b/futures-util/src/future/flatten_stream.rs @@ -46,7 +46,7 @@ impl Stream for FlattenStream { type Item = ::Item; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { loop { // safety: data is never moved via the resulting &mut reference let stream = match &mut unsafe { Pin::get_mut_unchecked(self.as_mut()) }.state { diff --git a/futures-util/src/future/fuse.rs b/futures-util/src/future/fuse.rs index 4866904c17..8913f6fe36 100644 --- a/futures-util/src/future/fuse.rs +++ b/futures-util/src/future/fuse.rs @@ -29,7 +29,7 @@ impl Fuse { impl Future for Fuse { type Output = Fut::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { // safety: we use this &mut only for matching, not for movement let v = match self.future().as_pin_mut() { Some(fut) => { diff --git a/futures-util/src/future/inspect.rs b/futures-util/src/future/inspect.rs index c5b3644e19..376327019b 100644 --- a/futures-util/src/future/inspect.rs +++ b/futures-util/src/future/inspect.rs @@ -34,7 +34,7 @@ impl Future for Inspect { type Output = Fut::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 2755d06427..a136c90869 100644 --- a/futures-util/src/future/into_stream.rs +++ b/futures-util/src/future/into_stream.rs @@ -25,7 +25,7 @@ impl IntoStream { impl Stream for IntoStream { type Item = Fut::Output; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let v = match self.future().as_pin_mut() { Some(fut) => { match fut.poll(cx) { diff --git a/futures-util/src/future/join.rs b/futures-util/src/future/join.rs index 4b7dd25869..69cc2adaa3 100644 --- a/futures-util/src/future/join.rs +++ b/futures-util/src/future/join.rs @@ -48,7 +48,7 @@ macro_rules! generate { #[allow(clippy::useless_let_if_seq)] fn poll( - mut self: Pin<&mut Self>, cx: &mut task::Context + mut self: Pin<&mut Self>, lw: &LocalWaker ) -> Poll { let mut all_done = true; $( diff --git a/futures-util/src/future/lazy.rs b/futures-util/src/future/lazy.rs index 9f0cedf2ee..af0ae7cbec 100644 --- a/futures-util/src/future/lazy.rs +++ b/futures-util/src/future/lazy.rs @@ -36,17 +36,17 @@ impl Unpin for Lazy {} /// # }); /// ``` pub fn lazy(f: F) -> Lazy - where F: FnOnce(&mut task::Context) -> R, + where F: FnOnce(&LocalWaker) -> R, { Lazy { f: Some(f) } } impl Future for Lazy - where F: FnOnce(&mut task::Context) -> R, + where F: FnOnce(&LocalWaker) -> R, { type Output = R; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 8cc46004ef..80e394c597 100644 --- a/futures-util/src/future/map.rs +++ b/futures-util/src/future/map.rs @@ -32,7 +32,7 @@ impl Future for Map { type Output = T; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 eb3890bf36..372ea00d3c 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -84,7 +84,7 @@ impl MaybeDone { impl Future for MaybeDone { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let res = unsafe { match Pin::get_mut_unchecked(self.as_mut()) { MaybeDone::Future(a) => { diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 364d227ca3..262b1891b1 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -676,7 +676,7 @@ pub trait FutureExt: Future { } /// A convenience for calling `Future::poll` on `Unpin` future types. - fn poll_unpin(&mut self, cx: &mut task::Context) -> Poll + fn poll_unpin(&mut self, lw: &LocalWaker) -> Poll where Self: Unpin + Sized { Pin::new(self).poll(cx) diff --git a/futures-util/src/future/option.rs b/futures-util/src/future/option.rs index c9a83098f5..470959c855 100644 --- a/futures-util/src/future/option.rs +++ b/futures-util/src/future/option.rs @@ -38,7 +38,7 @@ impl Future for OptionFuture { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll { match self.option().as_pin_mut() { Some(x) => x.poll(cx).map(Some), diff --git a/futures-util/src/future/poll_fn.rs b/futures-util/src/future/poll_fn.rs index d86920e004..555082cc90 100644 --- a/futures-util/src/future/poll_fn.rs +++ b/futures-util/src/future/poll_fn.rs @@ -28,7 +28,7 @@ impl Unpin for PollFn {} /// use futures::future::poll_fn; /// use futures::task::{self, Poll}; /// -/// fn read_line(cx: &mut task::Context) -> Poll { +/// fn read_line(lw: &LocalWaker) -> Poll { /// Poll::Ready("Hello, World!".into()) /// } /// @@ -38,17 +38,17 @@ impl Unpin for PollFn {} /// ``` pub fn poll_fn(f: F) -> PollFn where - F: FnMut(&mut task::Context) -> Poll + F: FnMut(&LocalWaker) -> Poll { PollFn { f } } impl Future for PollFn - where F: FnMut(&mut task::Context) -> Poll, + where F: FnMut(&LocalWaker) -> Poll, { type Output = T; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { (&mut self.f)(cx) } } diff --git a/futures-util/src/future/ready.rs b/futures-util/src/future/ready.rs index ccd96b3d4d..e69930003d 100644 --- a/futures-util/src/future/ready.rs +++ b/futures-util/src/future/ready.rs @@ -16,7 +16,7 @@ impl Future for Ready { type Output = T; #[inline] - fn poll(mut self: Pin<&mut Self>, _cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, _lw: &LocalWaker) -> Poll { Poll::Ready(self.0.take().unwrap()) } } diff --git a/futures-util/src/future/shared.rs b/futures-util/src/future/shared.rs index a005d3d8ac..2f92a3a94d 100644 --- a/futures-util/src/future/shared.rs +++ b/futures-util/src/future/shared.rs @@ -105,7 +105,7 @@ where } /// Registers the current task to receive a wakeup when `Inner` is awoken. - fn set_waker(&mut self, cx: &mut task::Context) { + fn set_waker(&mut self, lw: &LocalWaker) { // Acquire the lock first before checking COMPLETE to ensure there // isn't a race. let mut wakers = self.inner.notifier.wakers.lock().unwrap(); @@ -150,7 +150,7 @@ where { type Output = Fut::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = &mut *self; this.set_waker(cx); diff --git a/futures-util/src/future/then.rs b/futures-util/src/future/then.rs index ae29f442b9..6c4aed6db2 100644 --- a/futures-util/src/future/then.rs +++ b/futures-util/src/future/then.rs @@ -35,7 +35,7 @@ impl Future for Then { type Output = Fut2::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 d534f95cd4..dcaded4119 100644 --- a/futures-util/src/future/unit_error.rs +++ b/futures-util/src/future/unit_error.rs @@ -29,7 +29,7 @@ impl Future for UnitError { type Output = Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 9cc60bd42d..dbda11484c 100644 --- a/futures-util/src/future/with_spawner.rs +++ b/futures-util/src/future/with_spawner.rs @@ -28,7 +28,7 @@ impl Future for WithSpawner { type Output = Fut::Output; - fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = unsafe { Pin::get_mut_unchecked(self) }; let fut = unsafe { Pin::new_unchecked(&mut this.future) }; let spawner = &mut this.spawner; diff --git a/futures-util/src/io/allow_std.rs b/futures-util/src/io/allow_std.rs index 2d4f1c723c..6c318fddef 100644 --- a/futures-util/src/io/allow_std.rs +++ b/futures-util/src/io/allow_std.rs @@ -73,18 +73,18 @@ impl io::Write for AllowStdIo where T: io::Write { } impl AsyncWrite for AllowStdIo where T: io::Write { - fn poll_write(&mut self, _: &mut task::Context, buf: &[u8]) + fn poll_write(&mut self, _: &LocalWaker, buf: &[u8]) -> Poll> { Poll::Ready(Ok(try_with_interrupt!(io::Write::write(&mut self.0, buf)))) } - fn poll_flush(&mut self, _: &mut task::Context) -> Poll> { + fn poll_flush(&mut self, _: &LocalWaker) -> Poll> { try_with_interrupt!(io::Write::flush(self)); Poll::Ready(Ok(())) } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { self.poll_flush(cx) } } @@ -107,7 +107,7 @@ impl io::Read for AllowStdIo where T: io::Read { } impl AsyncRead for AllowStdIo where T: io::Read { - fn poll_read(&mut self, _: &mut task::Context, buf: &mut [u8]) + fn poll_read(&mut self, _: &LocalWaker, buf: &mut [u8]) -> Poll> { Poll::Ready(Ok(try_with_interrupt!(io::Read::read(&mut self.0, buf)))) diff --git a/futures-util/src/io/close.rs b/futures-util/src/io/close.rs index e3126ed40e..8c6a1dd220 100644 --- a/futures-util/src/io/close.rs +++ b/futures-util/src/io/close.rs @@ -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: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 cfa547b587..b0b8ba94db 100644 --- a/futures-util/src/io/copy_into.rs +++ b/futures-util/src/io/copy_into.rs @@ -46,7 +46,7 @@ impl Future for CopyInto<'_, R, W> { type Output = io::Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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/disabled/lines.rs b/futures-util/src/io/disabled/lines.rs index d21a6322a8..933ba277e1 100644 --- a/futures-util/src/io/disabled/lines.rs +++ b/futures-util/src/io/disabled/lines.rs @@ -45,7 +45,7 @@ impl Stream for Lines type Item = String; type Error = io::Error; - fn poll(&mut self, cx: &mut task::Context) -> Poll, io::Error> { + fn poll(&mut self, lw: &LocalWaker) -> Poll, io::Error> { let n = ready!(self.io.read_line(&mut self.line)); if n == 0 && self.line.len() == 0 { return Ok(None.into()) diff --git a/futures-util/src/io/flush.rs b/futures-util/src/io/flush.rs index b83293e177..7527c87b7d 100644 --- a/futures-util/src/io/flush.rs +++ b/futures-util/src/io/flush.rs @@ -32,7 +32,7 @@ impl Future for Flush<'_, W> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { self.writer.poll_flush(cx) } } diff --git a/futures-util/src/io/read.rs b/futures-util/src/io/read.rs index 6b0e878692..f015053cb7 100644 --- a/futures-util/src/io/read.rs +++ b/futures-util/src/io/read.rs @@ -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: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 45824cba7b..837e80e614 100644 --- a/futures-util/src/io/read_exact.rs +++ b/futures-util/src/io/read_exact.rs @@ -29,7 +29,7 @@ impl<'a, R: AsyncRead + ?Sized> ReadExact<'a, R> { impl Future for ReadExact<'_, R> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 55bd3dec3a..6c76a944bd 100644 --- a/futures-util/src/io/read_to_end.rs +++ b/futures-util/src/io/read_to_end.rs @@ -46,7 +46,7 @@ impl Drop for Guard<'_> { // readers, we need to make sure to truncate that if any of this panics. fn read_to_end_internal( rd: &mut R, - cx: &mut task::Context, + lw: &LocalWaker, buf: &mut Vec, ) -> Poll> { let mut g = Guard { len: buf.len(), buf }; @@ -83,7 +83,7 @@ impl Future for ReadToEnd<'_, A> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 d5676bdc0e..81e4f92d42 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -18,10 +18,10 @@ pub struct WriteHalf { fn lock_and_then( lock: &BiLock, - cx: &mut task::Context, + lw: &LocalWaker, f: F ) -> Poll> - where F: FnOnce(&mut T, &mut task::Context) -> Poll> + where F: FnOnce(&mut T, &LocalWaker) -> Poll> { match lock.poll_lock(cx) { // Safety: the value behind the bilock used by `ReadHalf` and `WriteHalf` is never exposed @@ -37,13 +37,13 @@ pub fn split(t: T) -> (ReadHalf, WriteHalf) { } impl AsyncRead for ReadHalf { - fn poll_read(&mut self, cx: &mut task::Context, buf: &mut [u8]) + fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_read(cx, buf)) } - fn poll_vectored_read(&mut self, cx: &mut task::Context, vec: &mut [&mut IoVec]) + fn poll_vectored_read(&mut self, lw: &LocalWaker, vec: &mut [&mut IoVec]) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_read(cx, vec)) @@ -51,23 +51,23 @@ impl AsyncRead for ReadHalf { } impl AsyncWrite for WriteHalf { - fn poll_write(&mut self, cx: &mut task::Context, buf: &[u8]) + fn poll_write(&mut self, lw: &LocalWaker, buf: &[u8]) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_write(cx, buf)) } - fn poll_vectored_write(&mut self, cx: &mut task::Context, vec: &[&IoVec]) + fn poll_vectored_write(&mut self, lw: &LocalWaker, vec: &[&IoVec]) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_write(cx, vec)) } - fn poll_flush(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_flush(&mut self, lw: &LocalWaker) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_flush(cx)) } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { lock_and_then(&self.handle, cx, |l, cx| l.poll_close(cx)) } } diff --git a/futures-util/src/io/write_all.rs b/futures-util/src/io/write_all.rs index 2dfa6c2c95..fd40a6ce91 100644 --- a/futures-util/src/io/write_all.rs +++ b/futures-util/src/io/write_all.rs @@ -29,7 +29,7 @@ impl<'a, W: AsyncWrite + ?Sized> WriteAll<'a, W> { impl Future for WriteAll<'_, W> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 33fb5787ab..d13e9ae2cb 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -37,7 +37,7 @@ macro_rules! delegate_sink { ($field:ident) => { fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut $crate::core_reexport::task::Context, + lw: &mut $crate::core_reexport::task::Context, ) -> $crate::core_reexport::task::Poll> { self.$field().poll_ready(cx) } @@ -51,14 +51,14 @@ macro_rules! delegate_sink { fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut $crate::core_reexport::task::Context + lw: &mut $crate::core_reexport::task::Context ) -> $crate::core_reexport::task::Poll> { self.$field().poll_flush(cx) } fn poll_close( mut self: Pin<&mut Self>, - cx: &mut $crate::core_reexport::task::Context + lw: &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 dbff4847a0..6fa6c3e043 100644 --- a/futures-util/src/lock.rs +++ b/futures-util/src/lock.rs @@ -87,7 +87,7 @@ impl BiLock { /// /// This function will panic if called outside the context of a future's /// task. - pub fn poll_lock(&self, cx: &mut task::Context) -> Poll> { + pub fn poll_lock(&self, lw: &LocalWaker) -> Poll> { loop { match self.arc.state.swap(1, SeqCst) { // Woohoo, we grabbed the lock! @@ -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: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { self.bilock.poll_lock(cx) } } diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index df0d5ae5f1..19a50d8e92 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -41,7 +41,7 @@ impl Buffer { fn try_empty_buffer( self: &mut Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { try_ready!(self.sink().poll_ready(cx)); while let Some(item) = self.buf().pop_front() { @@ -60,7 +60,7 @@ impl Buffer { impl Stream for Buffer where S: Sink + Stream { type Item = S::Item; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { self.sink().poll_next(cx) } } @@ -71,7 +71,7 @@ impl Sink for Buffer { fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.capacity() == 0 { return self.sink().poll_ready(cx); @@ -102,7 +102,7 @@ impl Sink for Buffer { fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { try_ready!(self.try_empty_buffer(cx)); debug_assert!(self.buf().is_empty()); @@ -111,7 +111,7 @@ impl Sink for Buffer { fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { try_ready!(self.try_empty_buffer(cx)); debug_assert!(self.buf().is_empty()); diff --git a/futures-util/src/sink/close.rs b/futures-util/src/sink/close.rs index 638d8a9a38..4e50a40d0d 100644 --- a/futures-util/src/sink/close.rs +++ b/futures-util/src/sink/close.rs @@ -26,7 +26,7 @@ impl Future for Close<'_, Si> { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { 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 42827ec3a2..ae947283d1 100644 --- a/futures-util/src/sink/drain.rs +++ b/futures-util/src/sink/drain.rs @@ -43,7 +43,7 @@ impl Sink for Drain { fn poll_ready( self: Pin<&mut Self>, - _cx: &mut task::Context, + _lw: &LocalWaker, ) -> Poll> { Poll::Ready(Ok(())) } @@ -57,14 +57,14 @@ impl Sink for Drain { fn poll_flush( self: Pin<&mut Self>, - _cx: &mut task::Context, + _lw: &LocalWaker, ) -> Poll> { Poll::Ready(Ok(())) } fn poll_close( self: Pin<&mut Self>, - _cx: &mut task::Context, + _lw: &LocalWaker, ) -> Poll> { Poll::Ready(Ok(())) } diff --git a/futures-util/src/sink/err_into.rs b/futures-util/src/sink/err_into.rs index ece8285898..c1fce81336 100644 --- a/futures-util/src/sink/err_into.rs +++ b/futures-util/src/sink/err_into.rs @@ -63,7 +63,7 @@ impl Stream for SinkErrInto fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_next(cx) } diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index aab4cb8a64..15dd1bc8e0 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -52,7 +52,7 @@ impl Sink for Fanout fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_ready(cx)).is_ready(); let sink2_ready = try_poll!(self.sink2().poll_ready(cx)).is_ready(); @@ -71,7 +71,7 @@ impl Sink for Fanout fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_flush(cx)).is_ready(); let sink2_ready = try_poll!(self.sink2().poll_flush(cx)).is_ready(); @@ -81,7 +81,7 @@ impl Sink for Fanout fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let sink1_ready = try_poll!(self.sink1().poll_close(cx)).is_ready(); let sink2_ready = try_poll!(self.sink2().poll_close(cx)).is_ready(); diff --git a/futures-util/src/sink/flush.rs b/futures-util/src/sink/flush.rs index cf6ddfa8be..8bec004258 100644 --- a/futures-util/src/sink/flush.rs +++ b/futures-util/src/sink/flush.rs @@ -32,7 +32,7 @@ impl Future for Flush<'_, Si> { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { 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 cda888b080..9da7ca0261 100644 --- a/futures-util/src/sink/map_err.rs +++ b/futures-util/src/sink/map_err.rs @@ -61,7 +61,7 @@ impl Sink for SinkMapErr fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 self.sink().poll_ready(cx).map_err(|e| self.take_f()(e)) @@ -77,7 +77,7 @@ impl Sink for SinkMapErr fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 self.sink().poll_flush(cx).map_err(|e| self.take_f()(e)) @@ -85,7 +85,7 @@ impl Sink for SinkMapErr fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 self.sink().poll_close(cx).map_err(|e| self.take_f()(e)) @@ -97,7 +97,7 @@ impl Stream for SinkMapErr { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_next(cx) } diff --git a/futures-util/src/sink/send.rs b/futures-util/src/sink/send.rs index 34ca7d663f..4ac438aec4 100644 --- a/futures-util/src/sink/send.rs +++ b/futures-util/src/sink/send.rs @@ -30,7 +30,7 @@ impl Future for Send<'_, Si> { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { let this = &mut *self; if let Some(item) = this.item.take() { diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index 2d5474d68b..5cbbb9939e 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -45,7 +45,7 @@ where fn try_start_send( &mut self, - cx: &mut task::Context, + lw: &LocalWaker, item: Si::SinkItem, ) -> Poll> { debug_assert!(self.buffered.is_none()); @@ -71,7 +71,7 @@ where fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { let this = &mut *self; // If we've got an item buffered already, we need to write it to the diff --git a/futures-util/src/sink/with.rs b/futures-util/src/sink/with.rs index 98722987c5..cfc44a7972 100644 --- a/futures-util/src/sink/with.rs +++ b/futures-util/src/sink/with.rs @@ -88,7 +88,7 @@ impl Stream for With fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_next(cx) } @@ -120,7 +120,7 @@ impl With fn poll( self: &mut Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let buffered = match self.state().as_pin_mut() { State::Empty => return Poll::Ready(Ok(())), @@ -149,7 +149,7 @@ impl Sink for With fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.poll(cx) } @@ -165,7 +165,7 @@ impl Sink for With fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { try_ready!(self.poll(cx)); try_ready!(self.sink().poll_flush(cx)); @@ -174,7 +174,7 @@ impl Sink for With fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { try_ready!(self.poll(cx)); try_ready!(self.sink().poll_close(cx)); diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 1e692f57b3..a3e83d38e1 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -76,7 +76,7 @@ where fn try_empty_stream( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let WithFlatMap { sink, stream, buffer, .. } = unsafe { Pin::get_mut_unchecked(self) }; @@ -116,7 +116,7 @@ where type Item = S::Item; fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_next(cx) } @@ -133,7 +133,7 @@ where fn poll_ready( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.try_empty_stream(cx) } @@ -150,7 +150,7 @@ where fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { match self.as_mut().try_empty_stream(cx) { Poll::Pending => Poll::Pending, @@ -161,7 +161,7 @@ where fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { match self.as_mut().try_empty_stream(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/stream/buffer_unordered.rs b/futures-util/src/stream/buffer_unordered.rs index 28864c20e8..cae2113400 100644 --- a/futures-util/src/stream/buffer_unordered.rs +++ b/futures-util/src/stream/buffer_unordered.rs @@ -108,7 +108,7 @@ where fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { // First up, try to spawn off as many futures as possible by filling up // our slab of futures. diff --git a/futures-util/src/stream/buffered.rs b/futures-util/src/stream/buffered.rs index 6fab7f66d1..3369760858 100644 --- a/futures-util/src/stream/buffered.rs +++ b/futures-util/src/stream/buffered.rs @@ -104,7 +104,7 @@ where fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { // Try to spawn off as many futures as possible by filling up // our in_progress_queue of futures. diff --git a/futures-util/src/stream/catch_unwind.rs b/futures-util/src/stream/catch_unwind.rs index 58a572b3f5..9861c79847 100644 --- a/futures-util/src/stream/catch_unwind.rs +++ b/futures-util/src/stream/catch_unwind.rs @@ -31,7 +31,7 @@ impl Stream for CatchUnwind fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.caught_unwind() { Poll::Ready(None) diff --git a/futures-util/src/stream/chain.rs b/futures-util/src/stream/chain.rs index ba12a74d93..a148e92097 100644 --- a/futures-util/src/stream/chain.rs +++ b/futures-util/src/stream/chain.rs @@ -38,7 +38,7 @@ where St1: Stream, fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if let Some(first) = self.first().as_pin_mut() { if let Some(item) = ready!(first.poll_next(cx)) { diff --git a/futures-util/src/stream/chunks.rs b/futures-util/src/stream/chunks.rs index 240bfd7e8c..b874888c82 100644 --- a/futures-util/src/stream/chunks.rs +++ b/futures-util/src/stream/chunks.rs @@ -68,7 +68,7 @@ impl Stream for Chunks { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let cap = self.items.capacity(); loop { diff --git a/futures-util/src/stream/collect.rs b/futures-util/src/stream/collect.rs index acc46228d1..46e59bd0b4 100644 --- a/futures-util/src/stream/collect.rs +++ b/futures-util/src/stream/collect.rs @@ -41,7 +41,7 @@ where St: Stream, { type Output = C; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 cae3713e7e..1dbccbc055 100644 --- a/futures-util/src/stream/concat.rs +++ b/futures-util/src/stream/concat.rs @@ -54,7 +54,7 @@ where St: Stream, type Output = St::Item; fn poll( - mut self: Pin<&mut Self>, cx: &mut task::Context + mut self: Pin<&mut Self>, lw: &LocalWaker ) -> 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 17cc6911d8..a176bdb1f0 100644 --- a/futures-util/src/stream/disabled/select_all.rs +++ b/futures-util/src/stream/disabled/select_all.rs @@ -69,7 +69,7 @@ impl Stream for SelectAll { fn poll_next( &mut self, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll, Self::Error> { match self.inner.poll_next(cx).map_err(|(err, _)| err)? { Async::Pending => Ok(Async::Pending), diff --git a/futures-util/src/stream/empty.rs b/futures-util/src/stream/empty.rs index 7b1bf2597c..031bae4312 100644 --- a/futures-util/src/stream/empty.rs +++ b/futures-util/src/stream/empty.rs @@ -26,7 +26,7 @@ impl Unpin for Empty {} impl Stream for Empty { type Item = T; - fn poll_next(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(None) } } diff --git a/futures-util/src/stream/filter.rs b/futures-util/src/stream/filter.rs index 67518e8fd7..f35e9fdfda 100644 --- a/futures-util/src/stream/filter.rs +++ b/futures-util/src/stream/filter.rs @@ -80,7 +80,7 @@ impl Stream for Filter fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { loop { if self.pending_fut().as_pin_mut().is_none() { diff --git a/futures-util/src/stream/filter_map.rs b/futures-util/src/stream/filter_map.rs index 0feddb87c9..48e818eb7c 100644 --- a/futures-util/src/stream/filter_map.rs +++ b/futures-util/src/stream/filter_map.rs @@ -73,7 +73,7 @@ impl Stream for FilterMap fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { loop { if self.pending().as_pin_mut().is_none() { diff --git a/futures-util/src/stream/flatten.rs b/futures-util/src/stream/flatten.rs index bffb283eb8..be52266196 100644 --- a/futures-util/src/stream/flatten.rs +++ b/futures-util/src/stream/flatten.rs @@ -65,7 +65,7 @@ impl Stream for Flatten fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { loop { if self.next().as_pin_mut().is_none() { diff --git a/futures-util/src/stream/fold.rs b/futures-util/src/stream/fold.rs index 9913244ba8..e190b25a82 100644 --- a/futures-util/src/stream/fold.rs +++ b/futures-util/src/stream/fold.rs @@ -46,7 +46,7 @@ impl Future for Fold { type Output = T; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { // we're currently processing a future to produce a new accum value if self.accum().is_none() { diff --git a/futures-util/src/stream/for_each.rs b/futures-util/src/stream/for_each.rs index 5f45b84601..b70914df96 100644 --- a/futures-util/src/stream/for_each.rs +++ b/futures-util/src/stream/for_each.rs @@ -48,7 +48,7 @@ impl Future for ForEach { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { loop { if let Some(future) = self.future().as_pin_mut() { ready!(future.poll(cx)); diff --git a/futures-util/src/stream/for_each_concurrent.rs b/futures-util/src/stream/for_each_concurrent.rs index ac47aa0c15..abc23a7512 100644 --- a/futures-util/src/stream/for_each_concurrent.rs +++ b/futures-util/src/stream/for_each_concurrent.rs @@ -55,7 +55,7 @@ impl Future for ForEachConcurrent { type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { loop { let mut made_progress_this_iter = false; diff --git a/futures-util/src/stream/forward.rs b/futures-util/src/stream/forward.rs index 4639f7b322..963c891928 100644 --- a/futures-util/src/stream/forward.rs +++ b/futures-util/src/stream/forward.rs @@ -46,7 +46,7 @@ where fn try_start_send( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, item: Si::SinkItem, ) -> Poll> { debug_assert!(self.buffered_item.is_none()); @@ -70,7 +70,7 @@ where fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { // If we've got an item buffered already, we need to write it to the // sink before we can do anything else diff --git a/futures-util/src/stream/fuse.rs b/futures-util/src/stream/fuse.rs index 37474a6c69..b59aa7abb2 100644 --- a/futures-util/src/stream/fuse.rs +++ b/futures-util/src/stream/fuse.rs @@ -75,7 +75,7 @@ impl Stream for Fuse { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.done() { return Poll::Ready(None); diff --git a/futures-util/src/stream/futures_ordered.rs b/futures-util/src/stream/futures_ordered.rs index 52cfb64d56..1b43ae32f5 100644 --- a/futures-util/src/stream/futures_ordered.rs +++ b/futures-util/src/stream/futures_ordered.rs @@ -49,7 +49,7 @@ impl Future for OrderWrapper fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { self.data().poll(cx) .map(|output| OrderWrapper { data: output, index: self.index }) @@ -172,7 +172,7 @@ impl Stream for FuturesOrdered { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { let this = &mut *self; diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index fda65f2684..d36a97ac72 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -254,7 +254,7 @@ impl FuturesUnordered { impl Stream for FuturesUnordered { type Item = Fut::Output; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut core_task::Context) + fn poll_next(mut self: Pin<&mut Self>, lw: &mut core_task::Context) -> Poll> { // Ensure `parent` is correctly set. diff --git a/futures-util/src/stream/inspect.rs b/futures-util/src/stream/inspect.rs index ab6649efe9..1f488eb158 100644 --- a/futures-util/src/stream/inspect.rs +++ b/futures-util/src/stream/inspect.rs @@ -59,7 +59,7 @@ impl Stream for Inspect fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { let item = ready!(self.stream().poll_next(cx)); Poll::Ready(item.map(|e| { diff --git a/futures-util/src/stream/into_future.rs b/futures-util/src/stream/into_future.rs index 4c75773b7c..a41095fab4 100644 --- a/futures-util/src/stream/into_future.rs +++ b/futures-util/src/stream/into_future.rs @@ -63,7 +63,7 @@ impl Future for StreamFuture { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll { let item = { let s = self.stream.as_mut().expect("polling StreamFuture twice"); diff --git a/futures-util/src/stream/iter.rs b/futures-util/src/stream/iter.rs index d0d101eb9e..56456c2ef4 100644 --- a/futures-util/src/stream/iter.rs +++ b/futures-util/src/stream/iter.rs @@ -40,7 +40,7 @@ impl Stream for Iter { type Item = I::Item; - fn poll_next(mut self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(self.iter.next()) } } diff --git a/futures-util/src/stream/map.rs b/futures-util/src/stream/map.rs index 186934a667..3e96d07a20 100644 --- a/futures-util/src/stream/map.rs +++ b/futures-util/src/stream/map.rs @@ -60,7 +60,7 @@ impl Stream for Map fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { let option = ready!(self.stream().poll_next(cx)); Poll::Ready(option.map(self.f())) diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index 6b346a892b..e13eeae1a5 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -1032,7 +1032,7 @@ pub trait StreamExt: Stream { /// stream types. fn poll_next_unpin( &mut self, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> where Self: Unpin + Sized { diff --git a/futures-util/src/stream/next.rs b/futures-util/src/stream/next.rs index d4dda448bb..4c0e4fa84a 100644 --- a/futures-util/src/stream/next.rs +++ b/futures-util/src/stream/next.rs @@ -24,7 +24,7 @@ impl Future for Next<'_, St> { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { 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 d060991aa8..e66e202359 100644 --- a/futures-util/src/stream/once.rs +++ b/futures-util/src/stream/once.rs @@ -40,7 +40,7 @@ impl Stream for Once { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let val = if let Some(f) = self.future().as_pin_mut() { ready!(f.poll(cx)) diff --git a/futures-util/src/stream/peek.rs b/futures-util/src/stream/peek.rs index e6dda913a1..18f003b09d 100644 --- a/futures-util/src/stream/peek.rs +++ b/futures-util/src/stream/peek.rs @@ -36,7 +36,7 @@ impl Peekable { /// to the next item if the stream is ready or passes through any errors. pub fn peek<'a>( self: &'a mut Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if self.peeked().is_some() { return Poll::Ready(self.peeked().as_ref()) @@ -56,7 +56,7 @@ impl Stream for Peekable { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { if let Some(item) = self.peeked().take() { return Poll::Ready(Some(item)) diff --git a/futures-util/src/stream/poll_fn.rs b/futures-util/src/stream/poll_fn.rs index f78ddd2e30..05f32a8004 100644 --- a/futures-util/src/stream/poll_fn.rs +++ b/futures-util/src/stream/poll_fn.rs @@ -37,18 +37,18 @@ impl Unpin for PollFn {} /// ``` pub fn poll_fn(f: F) -> PollFn where - F: FnMut(&mut task::Context) -> Poll>, + F: FnMut(&LocalWaker) -> Poll>, { PollFn { f } } impl Stream for PollFn where - F: FnMut(&mut task::Context) -> Poll>, + F: FnMut(&LocalWaker) -> Poll>, { type Item = T; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { (&mut self.f)(cx) } } diff --git a/futures-util/src/stream/repeat.rs b/futures-util/src/stream/repeat.rs index 6be7c87ab6..6b2a13360d 100644 --- a/futures-util/src/stream/repeat.rs +++ b/futures-util/src/stream/repeat.rs @@ -38,7 +38,7 @@ impl Stream for Repeat { type Item = T; - fn poll_next(self: Pin<&mut Self>, _: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, _: &LocalWaker) -> Poll> { Poll::Ready(Some(self.item.clone())) } } diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index cfc0f9de09..e53b7a5ecb 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -44,7 +44,7 @@ impl Stream for Select fn poll_next( self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { let Select { flag, stream1, stream2 } = unsafe { Pin::get_mut_unchecked(self) }; @@ -63,7 +63,7 @@ fn poll_inner( flag: &mut bool, a: Pin<&mut St1>, b: Pin<&mut St2>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> where St1: Stream, St2: Stream { diff --git a/futures-util/src/stream/skip.rs b/futures-util/src/stream/skip.rs index 25e7e96f30..95e1c3a270 100644 --- a/futures-util/src/stream/skip.rs +++ b/futures-util/src/stream/skip.rs @@ -56,7 +56,7 @@ impl Stream for Skip { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { while *self.remaining() > 0 { match ready!(self.stream().poll_next(cx)) { diff --git a/futures-util/src/stream/skip_while.rs b/futures-util/src/stream/skip_while.rs index c709df8c98..0166c4201a 100644 --- a/futures-util/src/stream/skip_while.rs +++ b/futures-util/src/stream/skip_while.rs @@ -75,7 +75,7 @@ impl Stream for SkipWhile fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.done_skipping() { return self.stream().poll_next(cx); diff --git a/futures-util/src/stream/split.rs b/futures-util/src/stream/split.rs index 40b0b9420e..67e994f97e 100644 --- a/futures-util/src/stream/split.rs +++ b/futures-util/src/stream/split.rs @@ -28,7 +28,7 @@ impl SplitStream { impl Stream for SplitStream { type Item = S::Item; - fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { match self.0.poll_lock(cx) { Poll::Ready(mut inner) => inner.as_pin_mut().poll_next(cx), Poll::Pending => Poll::Pending, @@ -68,7 +68,7 @@ impl Sink for SplitSink { type SinkItem = S::SinkItem; type SinkError = S::SinkError; - fn poll_ready(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { loop { if self.slot.is_none() { return Poll::Ready(Ok(())); @@ -82,7 +82,7 @@ impl Sink for SplitSink { Ok(()) } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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: Pin<&mut Self>, cx: &mut task::Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 a8275de5b1..28bbc6ff10 100644 --- a/futures-util/src/stream/take.rs +++ b/futures-util/src/stream/take.rs @@ -58,7 +58,7 @@ impl Stream for Take fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { if *self.remaining() == 0 { Poll::Ready(None) diff --git a/futures-util/src/stream/take_while.rs b/futures-util/src/stream/take_while.rs index b3518ab85e..2f2de43d62 100644 --- a/futures-util/src/stream/take_while.rs +++ b/futures-util/src/stream/take_while.rs @@ -75,7 +75,7 @@ impl Stream for TakeWhile fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.done_taking() { return Poll::Ready(None); diff --git a/futures-util/src/stream/then.rs b/futures-util/src/stream/then.rs index e71b095464..34482d4bbf 100644 --- a/futures-util/src/stream/then.rs +++ b/futures-util/src/stream/then.rs @@ -45,7 +45,7 @@ impl Stream for Then fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { if self.future().as_pin_mut().is_none() { let item = match ready!(self.stream().poll_next(cx)) { diff --git a/futures-util/src/stream/unfold.rs b/futures-util/src/stream/unfold.rs index 437f3bad34..d5aab6570a 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -86,7 +86,7 @@ impl Stream for Unfold fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { if let Some(state) = self.state().take() { let fut = (self.f())(state); diff --git a/futures-util/src/stream/zip.rs b/futures-util/src/stream/zip.rs index 0b195204c5..650bc12fcb 100644 --- a/futures-util/src/stream/zip.rs +++ b/futures-util/src/stream/zip.rs @@ -44,7 +44,7 @@ impl Stream for Zip fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context + lw: &LocalWaker ) -> Poll> { if self.queued1().is_none() { match self.stream1().poll_next(cx) { diff --git a/futures-util/src/task/atomic_waker.rs b/futures-util/src/task/atomic_waker.rs index af7cb58b1b..73e64273b1 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-util/src/task/atomic_waker.rs @@ -184,7 +184,7 @@ impl AtomicWaker { /// impl Future for Flag { /// type Output = (); /// - /// fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { + /// fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 716fb4b867..d1580a8a31 100644 --- a/futures-util/src/task/spawn/spawn_with_handle.rs +++ b/futures-util/src/task/spawn/spawn_with_handle.rs @@ -33,7 +33,7 @@ impl JoinHandle { impl Future for JoinHandle { type Output = T; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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: Pin<&mut Self>, cx: &mut task::Context) -> Poll<()> { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 e766620f87..0bfeb3b47b 100644 --- a/futures-util/src/try_future/and_then.rs +++ b/futures-util/src/try_future/and_then.rs @@ -32,7 +32,7 @@ impl Future for AndThen { type Output = Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> 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 839134bc71..cdbd917028 100644 --- a/futures-util/src/try_future/err_into.rs +++ b/futures-util/src/try_future/err_into.rs @@ -33,7 +33,7 @@ impl Future for ErrInto fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { self.future().try_poll(cx) .map(|res| res.map_err(Into::into)) diff --git a/futures-util/src/try_future/flatten_sink.rs b/futures-util/src/try_future/flatten_sink.rs index 954875a368..719214ca23 100644 --- a/futures-util/src/try_future/flatten_sink.rs +++ b/futures-util/src/try_future/flatten_sink.rs @@ -52,7 +52,7 @@ where fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let resolved_stream = match self.as_mut().project_pin() { Ready(s) => return s.poll_ready(cx), @@ -80,7 +80,7 @@ where fn poll_flush( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { match self.project_pin() { Ready(s) => s.poll_flush(cx), @@ -92,7 +92,7 @@ where fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { let res = match self.as_mut().project_pin() { Ready(s) => s.poll_close(cx), diff --git a/futures-util/src/try_future/into_future.rs b/futures-util/src/try_future/into_future.rs index 6f2c202ded..5b80dc61bb 100644 --- a/futures-util/src/try_future/into_future.rs +++ b/futures-util/src/try_future/into_future.rs @@ -25,7 +25,7 @@ impl Future for IntoFuture { #[inline] fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> 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 fc7395f6d7..ade244e24d 100644 --- a/futures-util/src/try_future/map_err.rs +++ b/futures-util/src/try_future/map_err.rs @@ -32,7 +32,7 @@ impl Future for MapErr fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { match self.future().try_poll(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/try_future/map_ok.rs b/futures-util/src/try_future/map_ok.rs index fd6382373f..9eb63e0fef 100644 --- a/futures-util/src/try_future/map_ok.rs +++ b/futures-util/src/try_future/map_ok.rs @@ -32,7 +32,7 @@ impl Future for MapOk fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { match self.future().try_poll(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/try_future/or_else.rs b/futures-util/src/try_future/or_else.rs index 18d64c0145..4ae9e48c22 100644 --- a/futures-util/src/try_future/or_else.rs +++ b/futures-util/src/try_future/or_else.rs @@ -34,7 +34,7 @@ impl Future for OrElse fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { self.try_chain().poll(cx, |result, async_op| { match result { diff --git a/futures-util/src/try_future/try_chain.rs b/futures-util/src/try_future/try_chain.rs index f9e9ebe52a..a424d8b6fd 100644 --- a/futures-util/src/try_future/try_chain.rs +++ b/futures-util/src/try_future/try_chain.rs @@ -27,7 +27,7 @@ impl TryChain pub(crate) fn poll( self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, f: F, ) -> Poll> where F: FnOnce(Result, Data) -> TryChainAction, diff --git a/futures-util/src/try_future/try_join.rs b/futures-util/src/try_future/try_join.rs index 7f4e0007d3..bebe0d6c9e 100644 --- a/futures-util/src/try_future/try_join.rs +++ b/futures-util/src/try_future/try_join.rs @@ -70,7 +70,7 @@ macro_rules! generate { #[allow(clippy::useless_let_if_seq)] fn poll( - mut self: Pin<&mut Self>, cx: &mut task::Context + mut self: Pin<&mut Self>, lw: &LocalWaker ) -> 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 ed212be9ec..bc01ad5d19 100644 --- a/futures-util/src/try_future/unwrap_or_else.rs +++ b/futures-util/src/try_future/unwrap_or_else.rs @@ -33,7 +33,7 @@ impl Future for UnwrapOrElse fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { match self.future().try_poll(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/try_stream/err_into.rs b/futures-util/src/try_stream/err_into.rs index aef01ab26b..7c35e2f622 100644 --- a/futures-util/src/try_stream/err_into.rs +++ b/futures-util/src/try_stream/err_into.rs @@ -31,7 +31,7 @@ where fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.stream().try_poll_next(cx) .map(|res| res.map(|some| some.map_err(Into::into))) diff --git a/futures-util/src/try_stream/into_stream.rs b/futures-util/src/try_stream/into_stream.rs index c421eecb61..2dfc5229e3 100644 --- a/futures-util/src/try_stream/into_stream.rs +++ b/futures-util/src/try_stream/into_stream.rs @@ -42,7 +42,7 @@ impl Stream for IntoStream { #[inline] fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> 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 3fb318575d..faa5745322 100644 --- a/futures-util/src/try_stream/map_err.rs +++ b/futures-util/src/try_stream/map_err.rs @@ -34,7 +34,7 @@ where #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { match self.stream().try_poll_next(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/try_stream/map_ok.rs b/futures-util/src/try_stream/map_ok.rs index 4e6a39e9c6..f90e53a101 100644 --- a/futures-util/src/try_stream/map_ok.rs +++ b/futures-util/src/try_stream/map_ok.rs @@ -34,7 +34,7 @@ where #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { match self.stream().try_poll_next(cx) { Poll::Pending => Poll::Pending, diff --git a/futures-util/src/try_stream/try_buffer_unordered.rs b/futures-util/src/try_stream/try_buffer_unordered.rs index 861734ca40..9db7e3abac 100644 --- a/futures-util/src/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/try_stream/try_buffer_unordered.rs @@ -71,7 +71,7 @@ impl Stream for TryBufferUnordered fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { // First up, try to spawn off as many futures as possible by filling up // our slab of futures. Propagate errors from the stream immediately. diff --git a/futures-util/src/try_stream/try_collect.rs b/futures-util/src/try_stream/try_collect.rs index 3fc35aced3..32704356e1 100644 --- a/futures-util/src/try_stream/try_collect.rs +++ b/futures-util/src/try_stream/try_collect.rs @@ -42,7 +42,7 @@ impl Future for TryCollect fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { loop { match ready!(self.stream().try_poll_next(cx)) { diff --git a/futures-util/src/try_stream/try_filter_map.rs b/futures-util/src/try_stream/try_filter_map.rs index f981634733..3f96df5e12 100644 --- a/futures-util/src/try_stream/try_filter_map.rs +++ b/futures-util/src/try_stream/try_filter_map.rs @@ -64,7 +64,7 @@ impl Stream for TryFilterMap fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll>> { loop { if self.pending().as_pin_mut().is_none() { diff --git a/futures-util/src/try_stream/try_fold.rs b/futures-util/src/try_stream/try_fold.rs index 3014d775be..1f8600f9a5 100644 --- a/futures-util/src/try_stream/try_fold.rs +++ b/futures-util/src/try_stream/try_fold.rs @@ -44,7 +44,7 @@ impl Future for TryFold { type Output = Result; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { // we're currently processing a future to produce a new accum value if self.accum().is_none() { diff --git a/futures-util/src/try_stream/try_for_each.rs b/futures-util/src/try_stream/try_for_each.rs index d24db4d434..3400dc8131 100644 --- a/futures-util/src/try_stream/try_for_each.rs +++ b/futures-util/src/try_stream/try_for_each.rs @@ -44,7 +44,7 @@ impl Future for TryForEach { type Output = Result<(), St::Error>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { if let Some(future) = self.future().as_pin_mut() { try_ready!(future.try_poll(cx)); 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 ab7d631713..b5b4cb20d7 100644 --- a/futures-util/src/try_stream/try_for_each_concurrent.rs +++ b/futures-util/src/try_stream/try_for_each_concurrent.rs @@ -55,7 +55,7 @@ impl Future for TryForEachConcurrent { type Output = Result<(), St::Error>; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { let mut made_progress_this_iter = false; diff --git a/futures-util/src/try_stream/try_next.rs b/futures-util/src/try_stream/try_next.rs index 46ca2897c8..9473daa280 100644 --- a/futures-util/src/try_stream/try_next.rs +++ b/futures-util/src/try_stream/try_next.rs @@ -26,7 +26,7 @@ impl Future for TryNext<'_, St> { fn poll( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll { match Pin::new(&mut *self.stream).try_poll_next(cx) { Poll::Ready(Some(Ok(x))) => Poll::Ready(Ok(Some(x))), diff --git a/futures-util/src/try_stream/try_skip_while.rs b/futures-util/src/try_stream/try_skip_while.rs index 56a4b38e8f..582b84230a 100644 --- a/futures-util/src/try_stream/try_skip_while.rs +++ b/futures-util/src/try_stream/try_skip_while.rs @@ -77,7 +77,7 @@ impl Stream for TrySkipWhile fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { if *self.done_skipping() { return self.stream().try_poll_next(cx); diff --git a/futures/tests/eager_drop.rs b/futures/tests/eager_drop.rs index 887f420840..6007530771 100644 --- a/futures/tests/eager_drop.rs +++ b/futures/tests/eager_drop.rs @@ -56,7 +56,7 @@ impl FutureData { impl Future for FutureData { type Output = F::Output; - fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { self.future().poll(cx) } } diff --git a/futures/tests/split.rs b/futures/tests/split.rs index b41412b37b..73f49b165f 100644 --- a/futures/tests/split.rs +++ b/futures/tests/split.rs @@ -22,7 +22,7 @@ impl Stream for Join { fn poll_next( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.stream().poll_next(cx) } @@ -34,7 +34,7 @@ impl Sink for Join { fn poll_ready( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_ready(cx) } @@ -48,14 +48,14 @@ impl Sink for Join { fn poll_flush( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_flush(cx) } fn poll_close( mut self: Pin<&mut Self>, - cx: &mut task::Context, + lw: &LocalWaker, ) -> Poll> { self.sink().poll_close(cx) } diff --git a/futures/tests_disabled/future_flatten_stream.rs b/futures/tests_disabled/future_flatten_stream.rs index 4930ff5f23..481b9b7a40 100644 --- a/futures/tests_disabled/future_flatten_stream.rs +++ b/futures/tests_disabled/future_flatten_stream.rs @@ -25,7 +25,7 @@ impl Stream for PanickingStream { type Item = T; type Error = E; - fn poll_next(&mut self, _: &mut task::Context) -> Poll, Self::Error> { + fn poll_next(&mut self, _: &LocalWaker) -> Poll, Self::Error> { panic!() } } diff --git a/futures/tests_disabled/sink.rs b/futures/tests_disabled/sink.rs index 44f4e37de5..d227af426a 100644 --- a/futures/tests_disabled/sink.rs +++ b/futures/tests_disabled/sink.rs @@ -98,14 +98,14 @@ impl Wake for Flag { } fn flag_cx(f: F) -> R - where F: FnOnce(Arc, &mut task::Context) -> R + where F: FnOnce(Arc, &LocalWaker) -> R { let flag = Flag::new(); let map = &mut task::LocalMap::new(); let waker = Waker::from(flag.clone()); let exec = &mut support::PanicExec; - let cx = &mut task::Context::new(map, &waker, exec); + let cx = &LocalWaker::new(map, &waker, exec); f(flag, cx) } @@ -122,7 +122,7 @@ impl Future for StartSendFut { type Item = S; type Error = S::SinkError; - fn poll(&mut self, cx: &mut task::Context) -> Poll { + fn poll(&mut self, lw: &LocalWaker) -> Poll { { let inner = self.0.as_mut().unwrap(); try_ready!(inner.poll_ready(cx)); @@ -222,7 +222,7 @@ impl Sink for ManualFlush { type SinkItem = Option; // Pass None to flush type SinkError = (); - fn poll_ready(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_ready(&mut self, _: &LocalWaker) -> Poll<(), Self::SinkError> { Ok(Async::Ready(())) } @@ -235,7 +235,7 @@ impl Sink for ManualFlush { Ok(()) } - fn poll_flush(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_flush(&mut self, lw: &LocalWaker) -> Poll<(), Self::SinkError> { if self.data.is_empty() { Ok(Async::Ready(())) } else { @@ -244,7 +244,7 @@ impl Sink for ManualFlush { } } - fn poll_close(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_close(&mut self, lw: &LocalWaker) -> Poll<(), Self::SinkError> { self.poll_flush(cx) } } @@ -317,7 +317,7 @@ impl Allow { } } - fn check(&self, cx: &mut task::Context) -> bool { + fn check(&self, lw: &LocalWaker) -> bool { if self.flag.get() { true } else { @@ -339,7 +339,7 @@ impl Sink for ManualAllow { type SinkItem = T; type SinkError = Never; - fn poll_ready(&mut self, cx: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_ready(&mut self, lw: &LocalWaker) -> Poll<(), Self::SinkError> { if self.allow.check(cx) { Ok(Async::Ready(())) } else { @@ -352,11 +352,11 @@ impl Sink for ManualAllow { Ok(()) } - fn poll_flush(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_flush(&mut self, _: &LocalWaker) -> Poll<(), Self::SinkError> { Ok(Async::Ready(())) } - fn poll_close(&mut self, _: &mut task::Context) -> Poll<(), Self::SinkError> { + fn poll_close(&mut self, _: &LocalWaker) -> Poll<(), Self::SinkError> { Ok(Async::Ready(())) } } diff --git a/futures/tests_disabled/stream.rs b/futures/tests_disabled/stream.rs index 7f604c791b..2ee7076660 100644 --- a/futures/tests_disabled/stream.rs +++ b/futures/tests_disabled/stream.rs @@ -25,7 +25,7 @@ impl Stream for Iter type Item = T; type Error = E; - fn poll_next(&mut self, _: &mut task::Context) -> Poll, E> { + fn poll_next(&mut self, _: &LocalWaker) -> Poll, E> { match self.iter.next() { Some(Ok(e)) => Ok(Async::Ready(Some(e))), Some(Err(e)) => Err(e), @@ -288,7 +288,7 @@ fn peek() { type Item = (); type Error = u32; - fn poll(&mut self, cx: &mut task::Context) -> Poll<(), u32> { + fn poll(&mut self, lw: &LocalWaker) -> Poll<(), u32> { { let res = try_ready!(self.inner.peek(cx)); assert_eq!(res, Some(&1)); From 778d42ff42e07e7f2db200af6c34f5781b38600c Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 24 Sep 2018 17:15:28 -0700 Subject: [PATCH 04/14] Update futures-core to new task API --- futures-core/src/future/future_obj.rs | 259 ++++++++++++++++++ futures-core/src/{future.rs => future/mod.rs} | 9 +- futures-core/src/stream/mod.rs | 38 ++- futures-core/src/stream/stream_obj.rs | 14 +- futures-core/src/task.rs | 7 +- 5 files changed, 289 insertions(+), 38 deletions(-) create mode 100644 futures-core/src/future/future_obj.rs rename futures-core/src/{future.rs => future/mod.rs} (83%) diff --git a/futures-core/src/future/future_obj.rs b/futures-core/src/future/future_obj.rs new file mode 100644 index 0000000000..cb5fc711a4 --- /dev/null +++ b/futures-core/src/future/future_obj.rs @@ -0,0 +1,259 @@ +use core::{ + fmt, mem, + future::Future, + marker::{PhantomData, Unpin}, + pin::Pin, + task::{LocalWaker, Poll}, +}; + +/// A custom trait object for polling futures, roughly akin to +/// `Box + 'a>`. +/// +/// This custom trait object was introduced for two reasons: +/// - Currently it is not possible to take `dyn Trait` by value and +/// `Box` is not available in no_std contexts. +/// - The `Future` trait is currently not object safe: The `Future::poll` +/// method makes uses the arbitrary self types feature and traits in which +/// this feature is used are currently not object safe due to current compiler +/// limitations. (See tracking issue for arbitrary self types for more +/// information #44874) +pub struct LocalFutureObj<'a, T> { + ptr: *mut (), + poll_fn: unsafe fn(*mut (), &LocalWaker) -> Poll, + drop_fn: unsafe fn(*mut ()), + _marker: PhantomData<&'a ()>, +} + +impl<'a, T> Unpin for LocalFutureObj<'a, T> {} + +impl<'a, T> LocalFutureObj<'a, T> { + /// Create a `LocalFutureObj` from a custom trait object representation. + #[inline] + pub fn new + 'a>(f: F) -> LocalFutureObj<'a, T> { + LocalFutureObj { + ptr: f.into_raw(), + poll_fn: F::poll, + drop_fn: F::drop, + _marker: PhantomData, + } + } + + /// Converts the `LocalFutureObj` into a `FutureObj` + /// To make this operation safe one has to ensure that the `UnsafeFutureObj` + /// instance from which this `LocalFutureObj` was created actually + /// implements `Send`. + #[inline] + pub unsafe fn into_future_obj(self) -> FutureObj<'a, T> { + FutureObj(self) + } +} + +impl<'a, T> fmt::Debug for LocalFutureObj<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("LocalFutureObj") + .finish() + } +} + +impl<'a, T> From> for LocalFutureObj<'a, T> { + #[inline] + fn from(f: FutureObj<'a, T>) -> LocalFutureObj<'a, T> { + f.0 + } +} + +impl<'a, T> Future for LocalFutureObj<'a, T> { + type Output = T; + + #[inline] + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { + unsafe { + ((*self).poll_fn)((*self).ptr, lw) + } + } +} + +impl<'a, T> Drop for LocalFutureObj<'a, T> { + fn drop(&mut self) { + unsafe { + (self.drop_fn)(self.ptr) + } + } +} + +/// A custom trait object for polling futures, roughly akin to +/// `Box + Send + 'a>`. +/// +/// This custom trait object was introduced for two reasons: +/// - Currently it is not possible to take `dyn Trait` by value and +/// `Box` is not available in no_std contexts. +/// - The `Future` trait is currently not object safe: The `Future::poll` +/// method makes uses the arbitrary self types feature and traits in which +/// this feature is used are currently not object safe due to current compiler +/// limitations. (See tracking issue for arbitrary self types for more +/// information #44874) +pub struct FutureObj<'a, T>(LocalFutureObj<'a, T>); + +impl<'a, T> Unpin for FutureObj<'a, T> {} +unsafe impl<'a, T> Send for FutureObj<'a, T> {} + +impl<'a, T> FutureObj<'a, T> { + /// Create a `FutureObj` from a custom trait object representation. + #[inline] + pub fn new + Send>(f: F) -> FutureObj<'a, T> { + FutureObj(LocalFutureObj::new(f)) + } +} + +impl<'a, T> fmt::Debug for FutureObj<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("FutureObj") + .finish() + } +} + +impl<'a, T> Future for FutureObj<'a, T> { + type Output = T; + + #[inline] + fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { + let pinned_field: Pin<&mut LocalFutureObj<'a, T>> = unsafe { + Pin::map_unchecked_mut(self, |x| &mut x.0) + }; + LocalFutureObj::poll(pinned_field, lw) + } +} + +/// A custom implementation of a future trait object for `FutureObj`, providing +/// a hand-rolled vtable. +/// +/// This custom representation is typically used only in `no_std` contexts, +/// where the default `Box`-based implementation is not available. +/// +/// The implementor must guarantee that it is safe to call `poll` repeatedly (in +/// a non-concurrent fashion) with the result of `into_raw` until `drop` is +/// called. +pub unsafe trait UnsafeFutureObj<'a, T>: 'a { + /// Convert an owned instance into a (conceptually owned) void pointer. + fn into_raw(self) -> *mut (); + + /// Poll the future represented by the given void pointer. + /// + /// # Safety + /// + /// The trait implementor must guarantee that it is safe to repeatedly call + /// `poll` with the result of `into_raw` until `drop` is called; such calls + /// are not, however, allowed to race with each other or with calls to + /// `drop`. + unsafe fn poll(ptr: *mut (), lw: &LocalWaker) -> Poll; + + /// Drops the future represented by the given void pointer. + /// + /// # Safety + /// + /// The trait implementor must guarantee that it is safe to call this + /// function once per `into_raw` invocation; that call cannot race with + /// other calls to `drop` or `poll`. + unsafe fn drop(ptr: *mut ()); +} + +unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F +where + F: Future + Unpin + 'a +{ + fn into_raw(self) -> *mut () { + self as *mut F as *mut () + } + + unsafe fn poll(ptr: *mut (), lw: &LocalWaker) -> Poll { + let p: Pin<&mut F> = Pin::new_unchecked(&mut *(ptr as *mut F)); + F::poll(p, lw) + } + + unsafe fn drop(_ptr: *mut ()) {} +} + +unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<&'a mut F> +where + F: Future + 'a +{ + fn into_raw(mut self) -> *mut () { + let mut_ref: &mut F = unsafe { Pin::get_mut_unchecked(Pin::as_mut(&mut self)) }; + mut_ref as *mut F as *mut () + } + + unsafe fn poll(ptr: *mut (), lw: &LocalWaker) -> Poll { + let future: Pin<&mut F> = Pin::new_unchecked(&mut *(ptr as *mut F)); + F::poll(future, lw) + } + + unsafe fn drop(_ptr: *mut ()) {} +} + +if_std! { + use std::boxed::Box; + + unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box + where F: Future + 'a + { + fn into_raw(self) -> *mut () { + Box::into_raw(self) as *mut () + } + + unsafe fn poll(ptr: *mut (), lw: &LocalWaker) -> Poll { + let ptr = ptr as *mut F; + let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); + F::poll(pin, lw) + } + + unsafe fn drop(ptr: *mut ()) { + drop(Box::from_raw(ptr as *mut F)) + } + } + + unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin> + where + F: Future + 'a + { + fn into_raw(mut self) -> *mut () { + let mut_ref: &mut F = unsafe { Pin::get_mut_unchecked(Pin::as_mut(&mut self)) }; + let ptr = mut_ref as *mut F as *mut (); + mem::forget(self); // Don't drop the box + ptr + } + + unsafe fn poll(ptr: *mut (), lw: &LocalWaker) -> Poll { + let ptr = ptr as *mut F; + let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); + F::poll(pin, lw) + } + + unsafe fn drop(ptr: *mut ()) { + drop(Box::from_raw(ptr as *mut Pin>)); + } + } + + impl<'a, F: Future + Send + 'a> From>> for FutureObj<'a, ()> { + fn from(boxed: Pin>) -> Self { + FutureObj::new(boxed) + } + } + + impl<'a, F: Future + Send + 'a> From> for FutureObj<'a, ()> { + fn from(boxed: Box) -> Self { + FutureObj::new(boxed) + } + } + + impl<'a, F: Future + 'a> From>> for LocalFutureObj<'a, ()> { + fn from(boxed: Pin>) -> Self { + LocalFutureObj::new(boxed) + } + } + + impl<'a, F: Future + 'a> From> for LocalFutureObj<'a, ()> { + fn from(boxed: Box) -> Self { + LocalFutureObj::new(boxed) + } + } +} diff --git a/futures-core/src/future.rs b/futures-core/src/future/mod.rs similarity index 83% rename from futures-core/src/future.rs rename to futures-core/src/future/mod.rs index bc8fa5f3a3..cc80ef43fb 100644 --- a/futures-core/src/future.rs +++ b/futures-core/src/future/mod.rs @@ -1,9 +1,12 @@ //! Futures. -use crate::task::{self, Poll}; +use crate::task::{LocalWaker, Poll}; use core::pin::Pin; -pub use core::future::{Future, FutureObj, LocalFutureObj, UnsafeFutureObj}; +pub use core::future::Future; + +mod future_obj; +pub use self::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj}; /// A convenience for futures that return `Result` values that includes /// a variety of adapters tailored to such futures. @@ -33,6 +36,6 @@ impl TryFuture for F #[inline] fn try_poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.poll(cx) + self.poll(lw) } } diff --git a/futures-core/src/stream/mod.rs b/futures-core/src/stream/mod.rs index 494b5d2809..17b0dff449 100644 --- a/futures-core/src/stream/mod.rs +++ b/futures-core/src/stream/mod.rs @@ -1,7 +1,8 @@ //! Asynchronous streams. -use crate::task::{self, Poll}; +use crate::task::{LocalWaker, Poll}; use core::marker::Unpin; +use core::ops; use core::pin::Pin; #[cfg(feature = "either")] @@ -64,18 +65,22 @@ impl<'a, S: ?Sized + Stream + Unpin> Stream for &'a mut S { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - S::poll_next(Pin::new(&mut **self), cx) + S::poll_next(Pin::new(&mut **self), lw) } } -impl<'a, S: ?Sized + Stream> Stream for Pin<&'a mut S> { - type Item = S::Item; +impl

Stream for Pin

+where + P: ops::DerefMut, + P::Target: Stream, +{ + type Item = ::Item; fn poll_next( - mut self: Pin<&mut Self>, + self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - S::poll_next((*self).as_mut(), cx) + Pin::get_mut(self).as_mut().poll_next(lw) } } @@ -89,8 +94,8 @@ impl Stream for Either fn poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { 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), + Either::Left(a) => Pin::new_unchecked(a).poll_next(lw), + Either::Right(b) => Pin::new_unchecked(b).poll_next(lw), } } } @@ -123,7 +128,7 @@ impl TryStream for S fn try_poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll>> { - self.poll_next(cx) + self.poll_next(lw) } } @@ -137,18 +142,7 @@ if_std! { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - Pin::new(&mut **self).poll_next(cx) - } - } - - impl Stream for Pin> { - type Item = S::Item; - - fn poll_next( - mut self: Pin<&mut Self>, - lw: &LocalWaker, - ) -> Poll> { - self.as_mut().poll_next(cx) + Pin::new(&mut **self).poll_next(lw) } } @@ -159,7 +153,7 @@ if_std! { self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }.poll_next(cx) + unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }.poll_next(lw) } } diff --git a/futures-core/src/stream/stream_obj.rs b/futures-core/src/stream/stream_obj.rs index ab146e980b..cc0f43d45f 100644 --- a/futures-core/src/stream/stream_obj.rs +++ b/futures-core/src/stream/stream_obj.rs @@ -1,5 +1,5 @@ use super::Stream; -use crate::task::{self, Poll}; +use crate::task::{LocalWaker, Poll}; use core::fmt; use core::marker::{PhantomData, Unpin}; use core::pin::Pin; @@ -67,7 +67,7 @@ impl<'a, T> Stream for LocalStreamObj<'a, T> { self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - unsafe { (self.poll_next_fn)(self.ptr, cx) } + unsafe { (self.poll_next_fn)(self.ptr, lw) } } } @@ -116,7 +116,7 @@ impl<'a, T> Stream for StreamObj<'a, T> { lw: &LocalWaker, ) -> Poll> { let pinned_field = unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }; - pinned_field.poll_next(cx) + pinned_field.poll_next(lw) } } @@ -168,7 +168,7 @@ where ptr: *mut (), lw: &LocalWaker, ) -> Poll> { - Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) + Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(lw) } unsafe fn drop(_ptr: *mut ()) {} @@ -186,7 +186,7 @@ where ptr: *mut (), lw: &LocalWaker, ) -> Poll> { - Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(cx) + Pin::new_unchecked(&mut *(ptr as *mut F)).poll_next(lw) } unsafe fn drop(_ptr: *mut ()) {} @@ -205,7 +205,7 @@ if_std! { unsafe fn poll_next(ptr: *mut (), lw: &LocalWaker) -> Poll> { let ptr = ptr as *mut F; let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); - pin.poll_next(cx) + pin.poll_next(lw) } unsafe fn drop(ptr: *mut ()) { @@ -223,7 +223,7 @@ if_std! { unsafe fn poll_next(ptr: *mut (), lw: &LocalWaker) -> Poll> { let ptr = ptr as *mut F; let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr); - pin.poll_next(cx) + pin.poll_next(lw) } unsafe fn drop(ptr: *mut ()) { diff --git a/futures-core/src/task.rs b/futures-core/src/task.rs index f0fbb614a1..b1fe40d285 100644 --- a/futures-core/src/task.rs +++ b/futures-core/src/task.rs @@ -1,11 +1,6 @@ //! Task notification. -pub use core::task::{ - Context, Poll, Spawn, - Waker, LocalWaker, UnsafeWake, - SpawnErrorKind, SpawnObjError, SpawnLocalObjError, -}; - +pub use core::task::{Poll, Waker, LocalWaker, UnsafeWake}; if_std! { pub use std::task::{Wake, local_waker, local_waker_from_nonlocal}; } From aa838912d742e5bea4aea2f30976f1a100149826 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 24 Sep 2018 17:18:38 -0700 Subject: [PATCH 05/14] Replaceall cx -> lw --- futures-channel/benches/sync_mpsc.rs | 42 ++++++------- futures-channel/src/mpsc/mod.rs | 14 ++--- futures-channel/src/oneshot.rs | 8 +-- futures-channel/tests/channel.rs | 4 +- futures-channel/tests/mpsc.rs | 42 ++++++------- futures-channel/tests/oneshot.rs | 18 +++--- futures-executor/benches/poll.rs | 6 +- futures-executor/benches/thread_notify.rs | 6 +- futures-executor/src/local_pool.rs | 8 +-- futures-executor/src/thread_pool.rs | 4 +- futures-executor/tests/local_pool.rs | 2 +- futures-io/src/lib.rs | 32 +++++----- futures-sink/src/channel_impls.rs | 6 +- futures-sink/src/lib.rs | 36 +++++------ futures-test/src/assert.rs | 12 ++-- futures-test/src/future/assert_unmoved.rs | 2 +- futures-test/src/future/mod.rs | 6 +- futures-test/src/future/pending_once.rs | 4 +- futures-test/src/task/context.rs | 4 +- futures-test/src/task/noop_spawner.rs | 10 ++-- futures-test/src/task/noop_waker.rs | 10 ++-- futures-test/src/task/panic_spawner.rs | 10 ++-- futures-test/src/task/panic_waker.rs | 10 ++-- futures-test/src/task/record_spawner.rs | 6 +- futures-test/src/task/wake_counter.rs | 8 +-- futures-util/benches/futures_unordered.rs | 4 +- futures-util/benches_disabled/bilock.rs | 16 ++--- futures-util/src/async_await/join.rs | 8 +-- futures-util/src/async_await/poll.rs | 2 +- futures-util/src/async_await/select.rs | 4 +- futures-util/src/async_await/spawn.rs | 8 +-- futures-util/src/compat/compat01to03.rs | 4 +- futures-util/src/compat/compat03to01.rs | 16 ++--- futures-util/src/future/abortable.rs | 4 +- futures-util/src/future/catch_unwind.rs | 2 +- futures-util/src/future/chain.rs | 4 +- futures-util/src/future/disabled/join_all.rs | 2 +- futures-util/src/future/disabled/select.rs | 4 +- .../src/future/disabled/select_all.rs | 2 +- futures-util/src/future/disabled/select_ok.rs | 2 +- futures-util/src/future/flatten.rs | 2 +- futures-util/src/future/flatten_stream.rs | 4 +- futures-util/src/future/fuse.rs | 2 +- futures-util/src/future/inspect.rs | 2 +- futures-util/src/future/into_stream.rs | 2 +- futures-util/src/future/join.rs | 2 +- futures-util/src/future/lazy.rs | 2 +- futures-util/src/future/map.rs | 2 +- futures-util/src/future/maybe_done.rs | 2 +- futures-util/src/future/mod.rs | 2 +- futures-util/src/future/option.rs | 2 +- futures-util/src/future/poll_fn.rs | 2 +- futures-util/src/future/shared.rs | 12 ++-- futures-util/src/future/then.rs | 2 +- futures-util/src/future/unit_error.rs | 2 +- futures-util/src/future/with_spawner.rs | 2 +- futures-util/src/io/allow_std.rs | 2 +- futures-util/src/io/close.rs | 2 +- futures-util/src/io/copy_into.rs | 6 +- futures-util/src/io/flush.rs | 2 +- futures-util/src/io/read.rs | 2 +- futures-util/src/io/read_exact.rs | 2 +- futures-util/src/io/read_to_end.rs | 4 +- futures-util/src/io/split.rs | 16 ++--- futures-util/src/io/write_all.rs | 2 +- futures-util/src/lib.rs | 6 +- futures-util/src/lock.rs | 4 +- futures-util/src/sink/buffer.rs | 18 +++--- futures-util/src/sink/close.rs | 2 +- futures-util/src/sink/err_into.rs | 2 +- futures-util/src/sink/fanout.rs | 12 ++-- futures-util/src/sink/flush.rs | 2 +- futures-util/src/sink/map_err.rs | 8 +-- futures-util/src/sink/send.rs | 4 +- futures-util/src/sink/send_all.rs | 12 ++-- futures-util/src/sink/with.rs | 14 ++--- futures-util/src/sink/with_flat_map.rs | 18 +++--- futures-util/src/stream/buffer_unordered.rs | 4 +- futures-util/src/stream/buffered.rs | 4 +- futures-util/src/stream/catch_unwind.rs | 2 +- futures-util/src/stream/chain.rs | 4 +- futures-util/src/stream/chunks.rs | 2 +- futures-util/src/stream/collect.rs | 2 +- futures-util/src/stream/concat.rs | 2 +- .../src/stream/disabled/select_all.rs | 2 +- futures-util/src/stream/filter.rs | 4 +- futures-util/src/stream/filter_map.rs | 4 +- futures-util/src/stream/flatten.rs | 4 +- futures-util/src/stream/fold.rs | 4 +- futures-util/src/stream/for_each.rs | 4 +- .../src/stream/for_each_concurrent.rs | 4 +- futures-util/src/stream/forward.rs | 12 ++-- futures-util/src/stream/fuse.rs | 2 +- futures-util/src/stream/futures_ordered.rs | 4 +- .../src/stream/futures_unordered/mod.rs | 8 +-- futures-util/src/stream/inspect.rs | 2 +- futures-util/src/stream/into_future.rs | 2 +- futures-util/src/stream/map.rs | 2 +- futures-util/src/stream/mod.rs | 2 +- futures-util/src/stream/next.rs | 2 +- futures-util/src/stream/once.rs | 2 +- futures-util/src/stream/peek.rs | 4 +- futures-util/src/stream/poll_fn.rs | 2 +- futures-util/src/stream/select.rs | 8 +-- futures-util/src/stream/skip.rs | 4 +- futures-util/src/stream/skip_while.rs | 6 +- futures-util/src/stream/split.rs | 18 +++--- futures-util/src/stream/take.rs | 2 +- futures-util/src/stream/take_while.rs | 4 +- futures-util/src/stream/then.rs | 4 +- futures-util/src/stream/unfold.rs | 2 +- futures-util/src/stream/zip.rs | 4 +- futures-util/src/task/atomic_waker.rs | 2 +- .../src/task/spawn/spawn_with_handle.rs | 6 +- futures-util/src/try_future/and_then.rs | 2 +- futures-util/src/try_future/err_into.rs | 2 +- futures-util/src/try_future/flatten_sink.rs | 10 ++-- futures-util/src/try_future/into_future.rs | 2 +- futures-util/src/try_future/map_err.rs | 2 +- futures-util/src/try_future/map_ok.rs | 2 +- futures-util/src/try_future/or_else.rs | 2 +- futures-util/src/try_future/try_chain.rs | 4 +- futures-util/src/try_future/try_join.rs | 4 +- futures-util/src/try_future/unwrap_or_else.rs | 2 +- futures-util/src/try_stream/err_into.rs | 2 +- futures-util/src/try_stream/into_stream.rs | 2 +- futures-util/src/try_stream/map_err.rs | 2 +- futures-util/src/try_stream/map_ok.rs | 2 +- .../src/try_stream/try_buffer_unordered.rs | 4 +- futures-util/src/try_stream/try_collect.rs | 2 +- futures-util/src/try_stream/try_filter_map.rs | 4 +- futures-util/src/try_stream/try_fold.rs | 4 +- futures-util/src/try_stream/try_for_each.rs | 4 +- .../src/try_stream/try_for_each_concurrent.rs | 4 +- futures-util/src/try_stream/try_next.rs | 2 +- futures-util/src/try_stream/try_skip_while.rs | 6 +- futures/tests/abortable.rs | 8 +-- futures/tests/eager_drop.rs | 2 +- futures/tests/fuse.rs | 6 +- futures/tests/futures_ordered.rs | 18 +++--- futures/tests/futures_unordered.rs | 18 +++--- futures/tests/split.rs | 8 +-- futures/tests_disabled/all.rs | 34 +++++------ futures/tests_disabled/ready_queue.rs | 48 +++++++-------- futures/tests_disabled/sink.rs | 60 +++++++++---------- futures/tests_disabled/stream.rs | 6 +- 146 files changed, 502 insertions(+), 502 deletions(-) diff --git a/futures-channel/benches/sync_mpsc.rs b/futures-channel/benches/sync_mpsc.rs index b17246b144..77e8ffedef 100644 --- a/futures-channel/benches/sync_mpsc.rs +++ b/futures-channel/benches/sync_mpsc.rs @@ -20,18 +20,18 @@ fn notify_noop() -> LocalWaker { task::local_waker_from_nonlocal(Arc::new(Noop)) } -fn noop_cx(f: impl FnOnce(&LocalWaker)) { +fn noop_lw(f: impl FnOnce(&LocalWaker)) { let pool = LocalPool::new(); let mut spawn = pool.spawner(); let waker = notify_noop(); - let cx = &LocalWaker::new(&waker, &mut spawn); - f(cx) + let lw = &LocalWaker::new(&waker, &mut spawn); + f(lw) } /// Single producer, single consumer #[bench] fn unbounded_1_tx(b: &mut Bencher) { - noop_cx(|cx| { + noop_lw(|lw| { b.iter(|| { let (tx, mut rx) = mpsc::unbounded(); @@ -40,12 +40,12 @@ fn unbounded_1_tx(b: &mut Bencher) { for i in 0..1000 { // Poll, not ready, park - assert_eq!(Poll::Pending, rx.poll_next_unpin(cx)); + assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); UnboundedSender::unbounded_send(&tx, i).unwrap(); // Now poll ready - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); } }) }) @@ -54,7 +54,7 @@ fn unbounded_1_tx(b: &mut Bencher) { /// 100 producers, single consumer #[bench] fn unbounded_100_tx(b: &mut Bencher) { - noop_cx(|cx| { + noop_lw(|lw| { b.iter(|| { let (tx, mut rx) = mpsc::unbounded(); @@ -63,11 +63,11 @@ fn unbounded_100_tx(b: &mut Bencher) { // 1000 send/recv operations total, result should be divided by 1000 for _ in 0..10 { for i in 0..tx.len() { - assert_eq!(Poll::Pending, rx.poll_next_unpin(cx)); + assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); UnboundedSender::unbounded_send(&tx[i], i).unwrap(); - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); } } }) @@ -76,14 +76,14 @@ fn unbounded_100_tx(b: &mut Bencher) { #[bench] fn unbounded_uncontended(b: &mut Bencher) { - noop_cx(|cx| { + noop_lw(|lw| { b.iter(|| { let (tx, mut rx) = mpsc::unbounded(); for i in 0..1000 { UnboundedSender::unbounded_send(&tx, i).expect("send"); // No need to create a task, because poll is not going to park. - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); } }) }) @@ -106,10 +106,10 @@ impl Stream for TestSender { let this = &mut *self; let mut tx = Pin::new(&mut this.tx); - ready!(tx.as_mut().poll_ready(cx)).unwrap(); + ready!(tx.as_mut().poll_ready(lw)).unwrap(); tx.as_mut().start_send(this.last + 1).unwrap(); this.last += 1; - assert_eq!(Poll::Ready(Ok(())), tx.as_mut().poll_flush(cx)); + assert_eq!(Poll::Ready(Ok(())), tx.as_mut().poll_flush(lw)); Poll::Ready(Some(this.last)) } } @@ -117,16 +117,16 @@ impl Stream for TestSender { /// Single producers, single consumer #[bench] fn bounded_1_tx(b: &mut Bencher) { - noop_cx(|cx| { + noop_lw(|lw| { b.iter(|| { let (tx, mut rx) = mpsc::channel(0); let mut tx = TestSender { tx, last: 0 }; for i in 0..1000 { - assert_eq!(Poll::Ready(Some(i + 1)), tx.poll_next_unpin(cx)); - assert_eq!(Poll::Pending, tx.poll_next_unpin(cx)); - assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i + 1)), tx.poll_next_unpin(lw)); + assert_eq!(Poll::Pending, tx.poll_next_unpin(lw)); + assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); } }) }) @@ -135,7 +135,7 @@ fn bounded_1_tx(b: &mut Bencher) { /// 100 producers, single consumer #[bench] fn bounded_100_tx(b: &mut Bencher) { - noop_cx(|cx| { + noop_lw(|lw| { b.iter(|| { // Each sender can send one item after specified capacity let (tx, mut rx) = mpsc::channel(0); @@ -150,11 +150,11 @@ fn bounded_100_tx(b: &mut Bencher) { for i in 0..10 { for j in 0..tx.len() { // Send an item - assert_eq!(Poll::Ready(Some(i + 1)), tx[j].poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i + 1)), tx[j].poll_next_unpin(lw)); // Then block - assert_eq!(Poll::Pending, tx[j].poll_next_unpin(cx)); + assert_eq!(Poll::Pending, tx[j].poll_next_unpin(lw)); // Recv the item - assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(cx)); + assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); } } }) diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index 9f43aea306..ca7facd444 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -483,7 +483,7 @@ impl Sender { // maintain internal consistency, a blank message is pushed onto the // parked task queue. if park_self { - self.park(cx); + self.park(lw); } self.queue_push_and_signal(Some(msg)); @@ -619,7 +619,7 @@ impl Sender { fn park(&mut self, lw: Option<&LocalWaker>) { // TODO: clean up internal state if the task::current will fail - let task = cx.map(|cx| cx.waker().clone()); + let task = lw.map(|lw| lw.waker().clone()); { let mut sender = self.sender_task.lock().unwrap(); @@ -660,7 +660,7 @@ impl Sender { })); } - self.poll_unparked(Some(cx)).map(Ok) + self.poll_unparked(Some(lw)).map(Ok) } /// Returns whether this channel is closed without needing a context. @@ -695,7 +695,7 @@ impl Sender { // // Update the task in case the `Sender` has been moved to another // task - task.task = cx.map(|cx| cx.waker().clone()); + task.task = lw.map(|lw| lw.waker().clone()); Poll::Pending } else { @@ -932,7 +932,7 @@ impl Receiver { return TryPark::NotEmpty; } - recv_task.task = Some(cx.waker().clone()); + recv_task.task = Some(lw.waker().clone()); TryPark::Parked } @@ -971,7 +971,7 @@ impl Stream for Receiver { // There are no messages to read, in this case, attempt to // park. The act of parking will verify that the channel is // still empty after the park operation has completed. - match self.try_park(cx) { + match self.try_park(lw) { TryPark::Parked => { // The task was parked, and the channel is still // empty, return Pending. @@ -1033,7 +1033,7 @@ impl Stream for UnboundedReceiver { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - Pin::new(&mut self.0).poll_next(cx) + Pin::new(&mut self.0).poll_next(lw) } } diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index d25ffcb9dc..86e4063ce6 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -177,7 +177,7 @@ impl Inner { // `Receiver` may have been dropped. The first thing it does is set the // flag, and if it fails to acquire the lock it assumes that we'll see // the flag later on. So... we then try to see the flag later on! - let handle = cx.waker().clone(); + let handle = lw.waker().clone(); match self.tx_task.try_lock() { Some(mut p) => *p = Some(handle), None => return Poll::Ready(()), @@ -261,7 +261,7 @@ impl Inner { let done = if self.complete.load(SeqCst) { true } else { - let task = cx.waker().clone(); + let task = lw.waker().clone(); match self.rx_task.try_lock() { Some(mut slot) => { *slot = Some(task); false }, None => true, @@ -350,7 +350,7 @@ impl Sender { /// however, is scheduled to receive a notification if the corresponding /// `Receiver` goes away. pub fn poll_cancel(&mut self, lw: &LocalWaker) -> Poll<()> { - self.inner.poll_cancel(cx) + self.inner.poll_cancel(lw) } /// Tests to see whether this `Sender`'s corresponding `Receiver` @@ -422,7 +422,7 @@ impl Future for Receiver { self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.inner.recv(cx) + self.inner.recv(lw) } } diff --git a/futures-channel/tests/channel.rs b/futures-channel/tests/channel.rs index a2af8b52f9..d2b3a38fbe 100644 --- a/futures-channel/tests/channel.rs +++ b/futures-channel/tests/channel.rs @@ -36,8 +36,8 @@ async fn send_sequence(n: u32, mut sender: mpsc::Sender) { fn drop_sender() { let (tx, mut rx) = mpsc::channel::(1); drop(tx); - let f = poll_fn(|cx| { - rx.poll_next_unpin(cx) + let f = poll_fn(|lw| { + rx.poll_next_unpin(lw) }); assert_eq!(block_on(f), None) } diff --git a/futures-channel/tests/mpsc.rs b/futures-channel/tests/mpsc.rs index 84a9cb00d1..182f20644c 100644 --- a/futures-channel/tests/mpsc.rs +++ b/futures-channel/tests/mpsc.rs @@ -28,34 +28,34 @@ fn send_recv() { #[test] fn send_recv_no_buffer() { // Run on a task context - block_on(poll_fn(move |cx| { + block_on(poll_fn(move |lw| { let (tx, rx) = mpsc::channel::(0); pin_mut!(tx, rx); - assert!(tx.as_mut().poll_flush(cx).is_ready()); - assert!(tx.as_mut().poll_ready(cx).is_ready()); + assert!(tx.as_mut().poll_flush(lw).is_ready()); + assert!(tx.as_mut().poll_ready(lw).is_ready()); // Send first message assert!(tx.as_mut().start_send(1).is_ok()); - assert!(tx.as_mut().poll_ready(cx).is_pending()); + assert!(tx.as_mut().poll_ready(lw).is_pending()); // poll_ready said Pending, so no room in buffer, therefore new sends // should get rejected with is_full. assert!(tx.as_mut().start_send(0).unwrap_err().is_full()); - assert!(tx.as_mut().poll_ready(cx).is_pending()); + assert!(tx.as_mut().poll_ready(lw).is_pending()); // Take the value - assert_eq!(rx.as_mut().poll_next(cx), Poll::Ready(Some(1))); - assert!(tx.as_mut().poll_ready(cx).is_ready()); + assert_eq!(rx.as_mut().poll_next(lw), Poll::Ready(Some(1))); + assert!(tx.as_mut().poll_ready(lw).is_ready()); // Send second message - assert!(tx.as_mut().poll_ready(cx).is_ready()); + assert!(tx.as_mut().poll_ready(lw).is_ready()); assert!(tx.as_mut().start_send(2).is_ok()); - assert!(tx.as_mut().poll_ready(cx).is_pending()); + assert!(tx.as_mut().poll_ready(lw).is_pending()); // Take the value - assert_eq!(rx.as_mut().poll_next(cx), Poll::Ready(Some(2))); - assert!(tx.as_mut().poll_ready(cx).is_ready()); + assert_eq!(rx.as_mut().poll_next(lw), Poll::Ready(Some(2))); + assert!(tx.as_mut().poll_ready(lw).is_ready()); Poll::Ready(()) })); @@ -118,11 +118,11 @@ fn recv_close_gets_none() { let (mut tx, mut rx) = mpsc::channel::(10); // Run on a task context - block_on(poll_fn(move |cx| { + block_on(poll_fn(move |lw| { rx.close(); - assert_eq!(rx.poll_next_unpin(cx), Poll::Ready(None)); - match tx.poll_ready(cx) { + assert_eq!(rx.poll_next_unpin(lw), Poll::Ready(None)); + match tx.poll_ready(lw) { Poll::Pending | Poll::Ready(Ok(_)) => panic!(), Poll::Ready(Err(e)) => assert!(e.is_disconnected()), }; @@ -138,9 +138,9 @@ fn tx_close_gets_none() { let (_, mut rx) = mpsc::channel::(10); // Run on a task context - block_on(poll_fn(move |cx| { - assert_eq!(rx.poll_next_unpin(cx), Poll::Ready(None)); - assert_eq!(rx.poll_next_unpin(cx), Poll::Ready(None)); + block_on(poll_fn(move |lw| { + assert_eq!(rx.poll_next_unpin(lw), Poll::Ready(None)); + assert_eq!(rx.poll_next_unpin(lw), Poll::Ready(None)); Poll::Ready(()) })); @@ -304,8 +304,8 @@ fn stress_receiver_multi_task_bounded_hard() { } else { // Just poll let n = n.clone(); - let f = poll_fn(move |cx| { - let r = match rx.poll_next_unpin(cx) { + let f = poll_fn(move |lw| { + let r = match rx.poll_next_unpin(lw) { Poll::Ready(Some(_)) => { n.fetch_add(1, Ordering::Relaxed); false @@ -475,8 +475,8 @@ fn try_send_2() { let (readytx, readyrx) = oneshot::channel::<()>(); let th = thread::spawn(move || { - block_on(poll_fn(|cx| { - assert!(tx.poll_ready(cx).is_pending()); + block_on(poll_fn(|lw| { + assert!(tx.poll_ready(lw).is_pending()); Poll::Ready(()) })); diff --git a/futures-channel/tests/oneshot.rs b/futures-channel/tests/oneshot.rs index 9acc8056fb..cd336edc88 100644 --- a/futures-channel/tests/oneshot.rs +++ b/futures-channel/tests/oneshot.rs @@ -12,12 +12,12 @@ use std::thread; fn smoke_poll() { let (mut tx, rx) = oneshot::channel::(); let mut rx = Some(rx); - let f = poll_fn(|cx| { - assert!(tx.poll_cancel(cx).is_pending()); - assert!(tx.poll_cancel(cx).is_pending()); + let f = poll_fn(|lw| { + assert!(tx.poll_cancel(lw).is_pending()); + assert!(tx.poll_cancel(lw).is_pending()); drop(rx.take()); - assert!(tx.poll_cancel(cx).is_ready()); - assert!(tx.poll_cancel(cx).is_ready()); + assert!(tx.poll_cancel(lw).is_ready()); + assert!(tx.poll_cancel(lw).is_ready()); Poll::Ready(()) }); @@ -43,7 +43,7 @@ impl Future for WaitForCancel { type Output = (); fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.tx.poll_cancel(cx) + self.tx.poll_cancel(lw) } } @@ -73,12 +73,12 @@ fn cancel_lots() { fn close() { let (mut tx, mut rx) = oneshot::channel::(); rx.close(); - block_on(poll_fn(|cx| { - match rx.poll_unpin(cx) { + block_on(poll_fn(|lw| { + match rx.poll_unpin(lw) { Poll::Ready(Err(_)) => {}, _ => panic!(), }; - assert!(tx.poll_cancel(cx).is_ready()); + assert!(tx.poll_cancel(lw).is_ready()); Poll::Ready(()) })); } diff --git a/futures-executor/benches/poll.rs b/futures-executor/benches/poll.rs index 21060a4220..56171315d7 100644 --- a/futures-executor/benches/poll.rs +++ b/futures-executor/benches/poll.rs @@ -42,7 +42,7 @@ fn task_init(b: &mut Bencher) { return Poll::Pending; } - let t = cx.waker().clone(); + let t = lw.waker().clone(); t.wake(); self.task = Some(t); @@ -59,10 +59,10 @@ fn task_init(b: &mut Bencher) { let pool = LocalPool::new(); let mut spawn = pool.spawner(); let waker = notify_noop(); - let mut cx = task::Context::new(&waker, &mut spawn); + let mut lw = task::Context::new(&waker, &mut spawn); b.iter(|| { fut.num = 0; - while let Poll::Pending = fut.poll_unpin(&mut cx) {} + while let Poll::Pending = fut.poll_unpin(&mut lw) {} }); } diff --git a/futures-executor/benches/thread_notify.rs b/futures-executor/benches/thread_notify.rs index 95ab1f5b39..c97bd572e9 100644 --- a/futures-executor/benches/thread_notify.rs +++ b/futures-executor/benches/thread_notify.rs @@ -23,7 +23,7 @@ fn thread_yield_single_thread_one_wait(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - cx.waker().wake(); + lw.waker().wake(); Poll::Pending } } @@ -51,7 +51,7 @@ fn thread_yield_single_thread_many_wait(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - cx.waker().wake(); + lw.waker().wake(); Poll::Pending } } @@ -88,7 +88,7 @@ fn thread_yield_multi_thread(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - self.tx.send(cx.waker().clone()).unwrap(); + self.tx.send(lw.waker().clone()).unwrap(); Poll::Pending } } diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index ded02fbc61..02f831cd5d 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -151,10 +151,10 @@ impl LocalPool { run_executor(|local_waker| { { - let mut main_cx = Context::new(local_waker, spawn); + let mut main_lw = Context::new(local_waker, spawn); // if our main task is done, so are we - let result = future.as_mut().poll(&mut main_cx); + let result = future.as_mut().poll(&mut main_lw); if let Poll::Ready(output) = result { return Poll::Ready(output); } @@ -172,7 +172,7 @@ impl LocalPool { where Sp: Spawn + Sized { // state for the FuturesUnordered, which will never be used - let mut pool_cx = Context::new(local_waker, spawn); + let mut pool_lw = Context::new(local_waker, spawn); loop { // empty the incoming queue of newly-spawned tasks @@ -183,7 +183,7 @@ impl LocalPool { } } - let ret = self.pool.poll_next_unpin(&mut pool_cx); + let ret = self.pool.poll_next_unpin(&mut pool_lw); // we queued up some new tasks; add them and poll again if !self.incoming.borrow().is_empty() { continue; diff --git a/futures-executor/src/thread_pool.rs b/futures-executor/src/thread_pool.rs index 19f247c64c..7acfd82c3d 100644 --- a/futures-executor/src/thread_pool.rs +++ b/futures-executor/src/thread_pool.rs @@ -299,8 +299,8 @@ impl Task { loop { let res = { - let mut cx = task::Context::new(&local_waker, &mut exec); - future.poll_unpin(&mut cx) + let mut lw = task::Context::new(&local_waker, &mut exec); + future.poll_unpin(&mut lw) }; match res { Poll::Pending => {} diff --git a/futures-executor/tests/local_pool.rs b/futures-executor/tests/local_pool.rs index 2483a523fb..c85541c20f 100644 --- a/futures-executor/tests/local_pool.rs +++ b/futures-executor/tests/local_pool.rs @@ -149,7 +149,7 @@ fn tasks_are_scheduled_fairly() { return Poll::Ready(()); } - cx.waker().wake(); + lw.waker().wake(); Poll::Pending } } diff --git a/futures-io/src/lib.rs b/futures-io/src/lib.rs index a26be38f1f..c113f14d59 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -106,7 +106,7 @@ if_std! { /// /// If no data is available for reading, the method returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object becomes + /// `lw.waker()`) to receive a notification when the object becomes /// readable or is closed. /// /// # Implementation @@ -128,7 +128,7 @@ if_std! { /// /// If no data is available for reading, the method returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object becomes + /// `lw.waker()`) to receive a notification when the object becomes /// readable or is closed. /// By default, this method delegates to using `poll_read` on the first /// buffer in `vec`. Objects which support vectored IO should override @@ -144,7 +144,7 @@ if_std! { -> Poll> { if let Some(ref mut first_iovec) = vec.get_mut(0) { - self.poll_read(cx, first_iovec) + self.poll_read(lw, first_iovec) } else { // `vec` is empty. Poll::Ready(Ok(0)) @@ -166,7 +166,7 @@ if_std! { /// /// If the object is not ready for writing, the method returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object becomes + /// `lw.waker()`) to receive a notification when the object becomes /// readable or is closed. /// /// # Implementation @@ -188,7 +188,7 @@ if_std! { /// /// If the object is not ready for writing, the method returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object becomes + /// `lw.waker()`) to receive a notification when the object becomes /// readable or is closed. /// /// By default, this method delegates to using `poll_write` on the first @@ -205,7 +205,7 @@ if_std! { -> Poll> { if let Some(ref first_iovec) = vec.get(0) { - self.poll_write(cx, &*first_iovec) + self.poll_write(lw, &*first_iovec) } else { // `vec` is empty. Poll::Ready(Ok(0)) @@ -219,7 +219,7 @@ if_std! { /// /// If flushing cannot immediately complete, this method returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object can make + /// `lw.waker()`) to receive a notification when the object can make /// progress towards flushing. /// /// # Implementation @@ -236,7 +236,7 @@ if_std! { /// /// If closing cannot immediately complete, this function returns /// `Ok(Async::Pending)` and arranges for the current task (via - /// `cx.waker()`) to receive a notification when the object can make + /// `lw.waker()`) to receive a notification when the object can make /// progress towards closing. /// /// # Implementation @@ -257,13 +257,13 @@ if_std! { fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll> { - (**self).poll_read(cx, buf) + (**self).poll_read(lw, buf) } fn poll_vectored_read(&mut self, lw: &LocalWaker, vec: &mut [&mut IoVec]) -> Poll> { - (**self).poll_vectored_read(cx, vec) + (**self).poll_vectored_read(lw, vec) } } } @@ -309,21 +309,21 @@ if_std! { fn poll_write(&mut self, lw: &LocalWaker, buf: &[u8]) -> Poll> { - (**self).poll_write(cx, buf) + (**self).poll_write(lw, buf) } fn poll_vectored_write(&mut self, lw: &LocalWaker, vec: &[&IoVec]) -> Poll> { - (**self).poll_vectored_write(cx, vec) + (**self).poll_vectored_write(lw, vec) } fn poll_flush(&mut self, lw: &LocalWaker) -> Poll> { - (**self).poll_flush(cx) + (**self).poll_flush(lw) } fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { - (**self).poll_close(cx) + (**self).poll_close(lw) } } } @@ -349,7 +349,7 @@ if_std! { } fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { - self.poll_flush(cx) + self.poll_flush(lw) } } } @@ -377,7 +377,7 @@ if_std! { } fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { - self.poll_flush(cx) + self.poll_flush(lw) } } diff --git a/futures-sink/src/channel_impls.rs b/futures-sink/src/channel_impls.rs index 9515ed5654..ecf2d98d4a 100644 --- a/futures-sink/src/channel_impls.rs +++ b/futures-sink/src/channel_impls.rs @@ -8,7 +8,7 @@ impl Sink for Sender { type SinkError = SendError; fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - (*self).poll_ready(cx) + (*self).poll_ready(lw) } fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { @@ -30,7 +30,7 @@ impl Sink for UnboundedSender { type SinkError = SendError; fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - UnboundedSender::poll_ready(&*self, cx) + UnboundedSender::poll_ready(&*self, lw) } fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { @@ -52,7 +52,7 @@ impl<'a, T> Sink for &'a UnboundedSender { type SinkError = SendError; fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - UnboundedSender::poll_ready(*self, cx) + UnboundedSender::poll_ready(*self, lw) } fn start_send(self: Pin<&mut Self>, msg: T) -> Result<(), Self::SinkError> { diff --git a/futures-sink/src/lib.rs b/futures-sink/src/lib.rs index 104a7af437..65968bb61a 100644 --- a/futures-sink/src/lib.rs +++ b/futures-sink/src/lib.rs @@ -60,7 +60,7 @@ pub trait Sink { /// /// This method returns `Poll::Ready` once the underlying sink is ready to /// receive data. If this method returns `Async::Pending`, the current task - /// is registered to be notified (via `cx.waker()`) when `poll_ready` + /// is registered to be notified (via `lw.waker()`) when `poll_ready` /// should be called again. /// /// In most cases, if the sink encounters an error, the sink will @@ -96,7 +96,7 @@ pub trait Sink { /// via `start_send` have been flushed. /// /// Returns `Ok(Async::Pending)` if there is more work left to do, in which - /// case the current task is scheduled (via `cx.waker()`) to wake up when + /// case the current task is scheduled (via `lw.waker()`) to wake up when /// `poll_flush` should be called again. /// /// In most cases, if the sink encounters an error, the sink will @@ -109,7 +109,7 @@ pub trait Sink { /// has been successfully closed. /// /// Returns `Ok(Async::Pending)` if there is more work left to do, in which - /// case the current task is scheduled (via `cx.waker()`) to wake up when + /// case the current task is scheduled (via `lw.waker()`) to wake up when /// `poll_close` should be called again. /// /// If this function encounters an error, the sink should be considered to @@ -122,7 +122,7 @@ impl<'a, S: ?Sized + Sink + Unpin> Sink for &'a mut S { type SinkError = S::SinkError; fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_ready(cx) + Pin::new(&mut **self).poll_ready(lw) } fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { @@ -130,11 +130,11 @@ impl<'a, S: ?Sized + Sink + Unpin> Sink for &'a mut S { } fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_flush(cx) + Pin::new(&mut **self).poll_flush(lw) } fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_close(cx) + Pin::new(&mut **self).poll_close(lw) } } @@ -143,7 +143,7 @@ impl<'a, S: ?Sized + Sink> Sink for Pin<&'a mut S> { type SinkError = S::SinkError; fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - S::poll_ready((*self).as_mut(), cx) + S::poll_ready((*self).as_mut(), lw) } fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { @@ -151,11 +151,11 @@ impl<'a, S: ?Sized + Sink> Sink for Pin<&'a mut S> { } fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - S::poll_flush((*self).as_mut(), cx) + S::poll_flush((*self).as_mut(), lw) } fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - S::poll_close((*self).as_mut(), cx) + S::poll_close((*self).as_mut(), lw) } } @@ -218,7 +218,7 @@ if_std! { type SinkError = S::SinkError; fn poll_ready(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_ready(cx) + Pin::new(&mut **self).poll_ready(lw) } fn start_send(mut self: Pin<&mut Self>, item: Self::SinkItem) -> Result<(), Self::SinkError> { @@ -226,11 +226,11 @@ if_std! { } fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_flush(cx) + Pin::new(&mut **self).poll_flush(lw) } fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - Pin::new(&mut **self).poll_close(cx) + Pin::new(&mut **self).poll_close(lw) } } } @@ -249,8 +249,8 @@ impl Sink for Either fn poll_ready(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { 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), + Either::Left(x) => Pin::new_unchecked(x).poll_ready(lw), + Either::Right(x) => Pin::new_unchecked(x).poll_ready(lw), } } } @@ -267,8 +267,8 @@ impl Sink for Either fn poll_flush(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { 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), + Either::Left(x) => Pin::new_unchecked(x).poll_flush(lw), + Either::Right(x) => Pin::new_unchecked(x).poll_flush(lw), } } } @@ -276,8 +276,8 @@ impl Sink for Either fn poll_close(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { unsafe { 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), + Either::Left(x) => Pin::new_unchecked(x).poll_close(lw), + Either::Right(x) => Pin::new_unchecked(x).poll_close(lw), } } } diff --git a/futures-test/src/assert.rs b/futures-test/src/assert.rs index b92ffab12a..0d669b97f3 100644 --- a/futures-test/src/assert.rs +++ b/futures-test/src/assert.rs @@ -31,9 +31,9 @@ macro_rules! assert_stream_pending { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); let stream = $crate::std_reexport::pin::Pin::new(stream); - let cx = &mut $crate::task::no_spawn_context(); + let lw = &mut $crate::task::no_spawn_context(); let poll = $crate::futures_core_reexport::stream::Stream::poll_next( - stream, cx, + stream, lw, ); if poll.is_ready() { panic!("assertion failed: stream is not pending"); @@ -68,8 +68,8 @@ macro_rules! assert_stream_next { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(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) { + let lw = &mut $crate::task::no_spawn_context(); + match $crate::futures_core_reexport::stream::Stream::poll_next(stream, lw) { $crate::futures_core_reexport::task::Poll::Ready(Some(x)) => { assert_eq!(x, $item); } @@ -111,8 +111,8 @@ macro_rules! assert_stream_done { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(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) { + let lw = &mut $crate::task::no_spawn_context(); + match $crate::futures_core_reexport::stream::Stream::poll_next(stream, lw) { $crate::futures_core_reexport::task::Poll::Ready(Some(_)) => { panic!("assertion failed: expected stream to be done but had more elements"); } diff --git a/futures-test/src/future/assert_unmoved.rs b/futures-test/src/future/assert_unmoved.rs index 3804e2fac2..8f53889e0c 100644 --- a/futures-test/src/future/assert_unmoved.rs +++ b/futures-test/src/future/assert_unmoved.rs @@ -43,7 +43,7 @@ impl Future for AssertUnmoved { } else { assert_eq!(self.this_ptr, cur_this, "Future moved between poll calls"); } - self.future().poll(cx) + self.future().poll(lw) } } diff --git a/futures-test/src/future/mod.rs b/futures-test/src/future/mod.rs index caf4de5837..399e42b288 100644 --- a/futures-test/src/future/mod.rs +++ b/futures-test/src/future/mod.rs @@ -43,10 +43,10 @@ pub trait FutureTestExt: Future { /// let future = (async { 5 }).pending_once(); /// pin_mut!(future); /// - /// let cx = &mut task::no_spawn_context(); + /// let lw = &mut task::no_spawn_context(); /// - /// assert_eq!(future.poll_unpin(cx), Poll::Pending); - /// assert_eq!(future.poll_unpin(cx), Poll::Ready(5)); + /// assert_eq!(future.poll_unpin(lw), Poll::Pending); + /// assert_eq!(future.poll_unpin(lw), Poll::Ready(5)); /// ``` fn pending_once(self) -> PendingOnce where diff --git a/futures-test/src/future/pending_once.rs b/futures-test/src/future/pending_once.rs index 810ef925df..05ad5ff747 100644 --- a/futures-test/src/future/pending_once.rs +++ b/futures-test/src/future/pending_once.rs @@ -36,10 +36,10 @@ impl Future for PendingOnce { lw: &LocalWaker, ) -> Poll { if *self.polled_before() { - self.future().poll(cx) + self.future().poll(lw) } else { *self.polled_before() = true; - cx.waker().wake(); + lw.waker().wake(); Poll::Pending } } diff --git a/futures-test/src/task/context.rs b/futures-test/src/task/context.rs index 3dd4ebb34d..d9d8b6c849 100644 --- a/futures-test/src/task/context.rs +++ b/futures-test/src/task/context.rs @@ -12,8 +12,8 @@ use futures_core::task::Context; /// #![feature(futures_api)] /// use futures_test::task; /// -/// let cx = task::panic_context(); -/// cx.waker().wake(); // Will panic +/// let lw = task::panic_context(); +/// lw.waker().wake(); // Will panic /// ``` pub fn panic_context() -> Context<'static> { Context::new(panic_local_waker_ref(), panic_spawner_mut()) diff --git a/futures-test/src/task/noop_spawner.rs b/futures-test/src/task/noop_spawner.rs index a46e9b3abe..3794ffe77c 100644 --- a/futures-test/src/task/noop_spawner.rs +++ b/futures-test/src/task/noop_spawner.rs @@ -11,11 +11,11 @@ use futures_core::task::{Spawn, SpawnObjError}; /// use futures::task::SpawnExt; /// use futures_test::task::{panic_context, NoopSpawner}; /// -/// let mut cx = panic_context(); +/// let mut lw = panic_context(); /// let mut spawn = NoopSpawner::new(); -/// let cx = &mut cx.with_spawner(&mut spawn); +/// let lw = &mut lw.with_spawner(&mut spawn); /// -/// cx.spawner().spawn(async { }); +/// lw.spawner().spawn(async { }); /// ``` #[derive(Debug)] pub struct NoopSpawner { @@ -53,12 +53,12 @@ impl Default for NoopSpawner { /// use futures::task::{self, SpawnExt}; /// use futures_test::task::{noop_local_waker_ref, noop_spawner_mut}; /// -/// let mut cx = task::Context::new( +/// let mut lw = task::Context::new( /// noop_local_waker_ref(), /// noop_spawner_mut(), /// ); /// -/// cx.spawner().spawn(async { }); +/// lw.spawner().spawn(async { }); /// ``` pub fn noop_spawner_mut() -> &'static mut NoopSpawner { Box::leak(Box::new(NoopSpawner::new())) diff --git a/futures-test/src/task/noop_waker.rs b/futures-test/src/task/noop_waker.rs index 63d5934c12..70e0a5aec1 100644 --- a/futures-test/src/task/noop_waker.rs +++ b/futures-test/src/task/noop_waker.rs @@ -12,10 +12,10 @@ use std::sync::Arc; /// #![feature(futures_api)] /// use futures_test::task::{panic_context, noop_local_waker_ref}; /// -/// let mut cx = panic_context(); -/// let cx = &mut cx.with_waker(noop_local_waker_ref()); +/// let mut lw = panic_context(); +/// let lw = &mut lw.with_waker(noop_local_waker_ref()); /// -/// cx.waker().wake(); +/// lw.waker().wake(); /// ``` #[derive(Debug)] pub struct NoopWake { @@ -75,12 +75,12 @@ pub fn noop_local_waker() -> LocalWaker { /// use futures::task; /// use futures_test::task::{noop_local_waker_ref, noop_spawner_mut}; /// -/// let mut cx = task::Context::new( +/// let mut lw = task::Context::new( /// noop_local_waker_ref(), /// noop_spawner_mut(), /// ); /// -/// cx.waker().wake(); +/// lw.waker().wake(); /// ``` pub fn noop_local_waker_ref() -> &'static LocalWaker { thread_local! { diff --git a/futures-test/src/task/panic_spawner.rs b/futures-test/src/task/panic_spawner.rs index 6c587367f2..9ed6ef21ce 100644 --- a/futures-test/src/task/panic_spawner.rs +++ b/futures-test/src/task/panic_spawner.rs @@ -11,11 +11,11 @@ use futures_core::task::{Spawn, SpawnObjError}; /// use futures::task::SpawnExt; /// use futures_test::task::{noop_context, PanicSpawner}; /// -/// let mut cx = noop_context(); +/// let mut lw = noop_context(); /// let mut spawn = PanicSpawner::new(); -/// let cx = &mut cx.with_spawner(&mut spawn); +/// let lw = &mut lw.with_spawner(&mut spawn); /// -/// cx.spawner().spawn(async { }); // Will panic +/// lw.spawner().spawn(async { }); // Will panic /// ``` #[derive(Debug)] pub struct PanicSpawner { @@ -53,12 +53,12 @@ impl Default for PanicSpawner { /// use futures::task::{self, SpawnExt}; /// use futures_test::task::{panic_local_waker_ref, panic_spawner_mut}; /// -/// let mut cx = task::Context::new( +/// let mut lw = task::Context::new( /// panic_local_waker_ref(), /// panic_spawner_mut(), /// ); /// -/// cx.spawner().spawn(async { }); // Will panic +/// lw.spawner().spawn(async { }); // Will panic /// ``` pub fn panic_spawner_mut() -> &'static mut PanicSpawner { Box::leak(Box::new(PanicSpawner::new())) diff --git a/futures-test/src/task/panic_waker.rs b/futures-test/src/task/panic_waker.rs index aaada5ec0a..0e54694f9b 100644 --- a/futures-test/src/task/panic_waker.rs +++ b/futures-test/src/task/panic_waker.rs @@ -12,10 +12,10 @@ use std::sync::Arc; /// #![feature(futures_api)] /// use futures_test::task::{noop_context, panic_local_waker_ref}; /// -/// let mut cx = noop_context(); -/// let cx = &mut cx.with_waker(panic_local_waker_ref()); +/// let mut lw = noop_context(); +/// let lw = &mut lw.with_waker(panic_local_waker_ref()); /// -/// cx.waker().wake(); // Will panic +/// lw.waker().wake(); // Will panic /// ``` #[derive(Debug)] pub struct PanicWake { @@ -79,12 +79,12 @@ pub fn panic_local_waker() -> LocalWaker { /// use futures::task; /// use futures_test::task::{panic_local_waker_ref, panic_spawner_mut}; /// -/// let mut cx = task::Context::new( +/// let mut lw = task::Context::new( /// panic_local_waker_ref(), /// panic_spawner_mut(), /// ); /// -/// cx.waker().wake(); // Will panic +/// lw.waker().wake(); // Will panic /// ``` pub fn panic_local_waker_ref() -> &'static LocalWaker { thread_local! { diff --git a/futures-test/src/task/record_spawner.rs b/futures-test/src/task/record_spawner.rs index 147359c22d..58733887f8 100644 --- a/futures-test/src/task/record_spawner.rs +++ b/futures-test/src/task/record_spawner.rs @@ -14,9 +14,9 @@ use futures_core::task::{Spawn, SpawnObjError}; /// let mut recorder = RecordSpawner::new(); /// /// { -/// let mut cx = panic_context(); -/// let cx = &mut cx.with_spawner(&mut recorder); -/// cx.spawner().spawn(async { }); +/// let mut lw = panic_context(); +/// let lw = &mut lw.with_spawner(&mut recorder); +/// lw.spawner().spawn(async { }); /// } /// /// assert_eq!(recorder.spawned().len(), 1); diff --git a/futures-test/src/task/wake_counter.rs b/futures-test/src/task/wake_counter.rs index 4dde15acf8..24920891af 100644 --- a/futures-test/src/task/wake_counter.rs +++ b/futures-test/src/task/wake_counter.rs @@ -12,13 +12,13 @@ use std::sync::Arc; /// use futures_test::task::{panic_context, WakeCounter}; /// /// let wake_counter = WakeCounter::new(); -/// let mut cx = panic_context(); -/// let cx = &mut cx.with_waker(wake_counter.local_waker()); +/// let mut lw = panic_context(); +/// let lw = &mut lw.with_waker(wake_counter.local_waker()); /// /// assert_eq!(wake_counter.count(), 0); /// -/// cx.waker().wake(); -/// cx.waker().wake(); +/// lw.waker().wake(); +/// lw.waker().wake(); /// /// assert_eq!(wake_counter.count(), 2); /// ``` diff --git a/futures-util/benches/futures_unordered.rs b/futures-util/benches/futures_unordered.rs index 759021741a..18e9fcf1d1 100644 --- a/futures-util/benches/futures_unordered.rs +++ b/futures-util/benches/futures_unordered.rs @@ -29,9 +29,9 @@ fn oneshots(b: &mut Bencher) { } }); - block_on(future::poll_fn(move |cx| { + block_on(future::poll_fn(move |lw| { loop { - if let Poll::Ready(None) = rxs.poll_next_unpin(cx) { + if let Poll::Ready(None) = rxs.poll_next_unpin(lw) { break } } diff --git a/futures-util/benches_disabled/bilock.rs b/futures-util/benches_disabled/bilock.rs index ac5f345da3..e8dbdf1428 100644 --- a/futures-util/benches_disabled/bilock.rs +++ b/futures-util/benches_disabled/bilock.rs @@ -46,7 +46,7 @@ impl Stream for LockStream { type Error = (); fn poll_next(&mut self, lw: &LocalWaker) -> Poll, Self::Error> { - self.lock.poll(cx).map(|a| match a { + self.lock.poll(lw).map(|a| match a { Async::Ready(a) => Async::Ready(Some(a)), Async::Pending => Async::Pending, }) @@ -60,7 +60,7 @@ fn contended(b: &mut Bencher) { let mut exec = pool.executor(); let waker = notify_noop(); let mut map = task::LocalMap::new(); - let mut cx = task::Context::new(&mut map, &waker, &mut exec); + let mut lw = task::Context::new(&mut map, &waker, &mut exec); b.iter(|| { let (x, y) = BiLock::new(1); @@ -69,20 +69,20 @@ fn contended(b: &mut Bencher) { let mut y = LockStream::new(y); for _ in 0..1000 { - let x_guard = match x.poll_next(&mut cx) { + let x_guard = match x.poll_next(&mut lw) { Ok(Async::Ready(Some(guard))) => guard, _ => panic!(), }; // Try poll second lock while first lock still holds the lock - match y.poll_next(&mut cx) { + match y.poll_next(&mut lw) { Ok(Async::Pending) => (), _ => panic!(), }; x.release_lock(x_guard); - let y_guard = match y.poll_next(&mut cx) { + let y_guard = match y.poll_next(&mut lw) { Ok(Async::Ready(Some(guard))) => guard, _ => panic!(), }; @@ -99,7 +99,7 @@ fn lock_unlock(b: &mut Bencher) { let mut exec = pool.executor(); let waker = notify_noop(); let mut map = task::LocalMap::new(); - let mut cx = task::Context::new(&mut map, &waker, &mut exec); + let mut lw = task::Context::new(&mut map, &waker, &mut exec); b.iter(|| { let (x, y) = BiLock::new(1); @@ -108,14 +108,14 @@ fn lock_unlock(b: &mut Bencher) { let mut y = LockStream::new(y); for _ in 0..1000 { - let x_guard = match x.poll_next(&mut cx) { + let x_guard = match x.poll_next(&mut lw) { Ok(Async::Ready(Some(guard))) => guard, _ => panic!(), }; x.release_lock(x_guard); - let y_guard = match y.poll_next(&mut cx) { + let y_guard = match y.poll_next(&mut lw) { Ok(Async::Ready(Some(guard))) => guard, _ => panic!(), }; diff --git a/futures-util/src/async_await/join.rs b/futures-util/src/async_await/join.rs index bb597d6461..da77c30cf6 100644 --- a/futures-util/src/async_await/join.rs +++ b/futures-util/src/async_await/join.rs @@ -29,11 +29,11 @@ macro_rules! join { // is no longer accessible by the end user. let mut $fut = $crate::future::maybe_done($fut); )* - await!($crate::future::poll_fn(move |cx| { + await!($crate::future::poll_fn(move |lw| { let mut all_done = true; $( if $crate::core_reexport::future::Future::poll( - unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, cx).is_pending() + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, lw).is_pending() { all_done = false; } @@ -97,11 +97,11 @@ macro_rules! try_join { let mut $fut = $crate::future::maybe_done($fut); )* - let res: $crate::core_reexport::result::Result<_, _> = await!($crate::future::poll_fn(move |cx| { + let res: $crate::core_reexport::result::Result<_, _> = await!($crate::future::poll_fn(move |lw| { let mut all_done = true; $( if $crate::core_reexport::future::Future::poll( - unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, cx).is_pending() + unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }, lw).is_pending() { all_done = false; } else if unsafe { $crate::core_reexport::pin::Pin::new_unchecked(&mut $fut) }.output_mut().unwrap().is_err() { diff --git a/futures-util/src/async_await/poll.rs b/futures-util/src/async_await/poll.rs index 588fc39194..08762b754a 100644 --- a/futures-util/src/async_await/poll.rs +++ b/futures-util/src/async_await/poll.rs @@ -28,6 +28,6 @@ pub struct PollOnce { impl Future for PollOnce { type Output = Poll; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - Poll::Ready(Pin::new(&mut self.future).poll(cx)) + Poll::Ready(Pin::new(&mut self.future).poll(lw)) } } diff --git a/futures-util/src/async_await/select.rs b/futures-util/src/async_await/select.rs index 136cfcb3a2..7357cc76ba 100644 --- a/futures-util/src/async_await/select.rs +++ b/futures-util/src/async_await/select.rs @@ -47,10 +47,10 @@ macro_rules! select { )* } - let __priv_res = await!($crate::future::poll_fn(|cx| { + let __priv_res = await!($crate::future::poll_fn(|lw| { $( match $crate::core_reexport::future::Future::poll( - $crate::core_reexport::pin::Pin::new(&mut $name), cx) + $crate::core_reexport::pin::Pin::new(&mut $name), lw) { $crate::core_reexport::task::Poll::Ready(x) => return $crate::core_reexport::task::Poll::Ready(__PrivResult::$name(x)), diff --git a/futures-util/src/async_await/spawn.rs b/futures-util/src/async_await/spawn.rs index 30374d3ed2..27b2b45048 100644 --- a/futures-util/src/async_await/spawn.rs +++ b/futures-util/src/async_await/spawn.rs @@ -20,8 +20,8 @@ #[macro_export] macro_rules! spawn { ($future:expr) => { - await!($crate::future::lazy(|cx| { - $crate::task::SpawnExt::spawn(cx.spawner(), $future) + await!($crate::future::lazy(|lw| { + $crate::task::SpawnExt::spawn(lw.spawner(), $future) })) } } @@ -51,8 +51,8 @@ macro_rules! spawn { #[macro_export] macro_rules! spawn_with_handle { ($future:expr) => { - await!($crate::future::lazy(|cx| { - $crate::task::SpawnExt::spawn_with_handle(cx.spawner(), $future) + await!($crate::future::lazy(|lw| { + $crate::task::SpawnExt::spawn_with_handle(lw.spawner(), $future) })) } } diff --git a/futures-util/src/compat/compat01to03.rs b/futures-util/src/compat/compat01to03.rs index d21a4a9769..a5da352341 100644 --- a/futures-util/src/compat/compat01to03.rs +++ b/futures-util/src/compat/compat01to03.rs @@ -14,7 +14,7 @@ impl Future03 for Compat { self: Pin<&mut Self>, lw: &mut task03::Context, ) -> task03::Poll { - let notify = &WakerToHandle(cx.waker()); + let notify = &WakerToHandle(lw.waker()); executor01::with_notify(notify, 0, move || { match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { @@ -33,7 +33,7 @@ impl Stream03 for Compat { self: Pin<&mut Self>, lw: &mut task03::Context, ) -> task03::Poll> { - let notify = &WakerToHandle(cx.waker()); + let notify = &WakerToHandle(lw.waker()); executor01::with_notify(notify, 0, move || { match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { diff --git a/futures-util/src/compat/compat03to01.rs b/futures-util/src/compat/compat03to01.rs index 98146297ed..d6fd5d3348 100644 --- a/futures-util/src/compat/compat03to01.rs +++ b/futures-util/src/compat/compat03to01.rs @@ -19,7 +19,7 @@ where type Error = Fut::Error; fn poll(&mut self) -> Poll01 { - with_context(self, |inner, cx| match inner.try_poll(cx) { + with_context(self, |inner, lw| match inner.try_poll(lw) { task03::Poll::Ready(Ok(t)) => Ok(Async01::Ready(t)), task03::Poll::Pending => Ok(Async01::NotReady), task03::Poll::Ready(Err(e)) => Err(e), @@ -36,7 +36,7 @@ where type Error = St::Error; fn poll(&mut self) -> Poll01, Self::Error> { - with_context(self, |inner, cx| match inner.try_poll_next(cx) { + with_context(self, |inner, lw| match inner.try_poll_next(lw) { task03::Poll::Ready(None) => Ok(Async01::Ready(None)), task03::Poll::Ready(Some(Ok(t))) => Ok(Async01::Ready(Some(t))), task03::Poll::Pending => Ok(Async01::NotReady), @@ -57,8 +57,8 @@ where &mut self, item: Self::SinkItem, ) -> StartSend01 { - with_context(self, |mut inner, cx| { - match inner.as_mut().poll_ready(cx) { + with_context(self, |mut inner, lw| { + match inner.as_mut().poll_ready(lw) { task03::Poll::Ready(Ok(())) => { inner.start_send(item).map(|()| AsyncSink01::Ready) } @@ -69,7 +69,7 @@ where } fn poll_complete(&mut self) -> Poll01<(), Self::SinkError> { - with_context(self, |inner, cx| match inner.poll_flush(cx) { + with_context(self, |inner, lw| match inner.poll_flush(lw) { task03::Poll::Ready(Ok(())) => Ok(Async01::Ready(())), task03::Poll::Pending => Ok(Async01::NotReady), task03::Poll::Ready(Err(e)) => Err(e), @@ -77,7 +77,7 @@ where } fn close(&mut self) -> Poll01<(), Self::SinkError> { - with_context(self, |inner, cx| match inner.poll_close(cx) { + with_context(self, |inner, lw| match inner.poll_close(lw) { task03::Poll::Ready(Ok(())) => Ok(Async01::Ready(())), task03::Poll::Pending => Ok(Async01::NotReady), task03::Poll::Ready(Err(e)) => Err(e), @@ -124,6 +124,6 @@ where { let waker = current_ref_as_waker(); let spawn = compat.spawn.as_mut().unwrap(); - let mut cx = task03::Context::new(&waker, spawn); - f(Pin::new(&mut compat.inner), &mut cx) + let mut lw = task03::Context::new(&waker, spawn); + f(Pin::new(&mut compat.inner), &mut lw) } diff --git a/futures-util/src/future/abortable.rs b/futures-util/src/future/abortable.rs index b50c8ba528..b4475103d9 100644 --- a/futures-util/src/future/abortable.rs +++ b/futures-util/src/future/abortable.rs @@ -129,12 +129,12 @@ impl Future for Abortable where Fut: Future { } // attempt to complete the future - if let Poll::Ready(x) = self.future().poll(cx) { + if let Poll::Ready(x) = self.future().poll(lw) { return Poll::Ready(Ok(x)) } // Register to receive a wakeup if the future is aborted in the... future - self.inner.waker.register(cx.waker()); + self.inner.waker.register(lw.waker()); // Check to see if the future was aborted between the first check and // registration. diff --git a/futures-util/src/future/catch_unwind.rs b/futures-util/src/future/catch_unwind.rs index c7714c9b66..4aa7d109d2 100644 --- a/futures-util/src/future/catch_unwind.rs +++ b/futures-util/src/future/catch_unwind.rs @@ -29,7 +29,7 @@ impl Future for CatchUnwind type Output = Result>; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - match catch_unwind(AssertUnwindSafe(|| self.future().poll(cx))) { + match catch_unwind(AssertUnwindSafe(|| self.future().poll(lw))) { 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 66e91e7fb2..3bb50aac90 100644 --- a/futures-util/src/future/chain.rs +++ b/futures-util/src/future/chain.rs @@ -33,13 +33,13 @@ impl Chain loop { let (output, data) = match this { Chain::First(fut1, data) => { - match unsafe { Pin::new_unchecked(fut1) }.poll(cx) { + match unsafe { Pin::new_unchecked(fut1) }.poll(lw) { Poll::Pending => return Poll::Pending, Poll::Ready(output) => (output, data.take().unwrap()), } } Chain::Second(fut2) => { - return unsafe { Pin::new_unchecked(fut2) }.poll(cx); + return unsafe { Pin::new_unchecked(fut2) }.poll(lw); } Chain::Empty => unreachable!() }; diff --git a/futures-util/src/future/disabled/join_all.rs b/futures-util/src/future/disabled/join_all.rs index a59b8377f1..0846ae24a3 100644 --- a/futures-util/src/future/disabled/join_all.rs +++ b/futures-util/src/future/disabled/join_all.rs @@ -93,7 +93,7 @@ impl Future for JoinAll for idx in 0 .. self.elems.len() { let done_val = match self.elems[idx] { ElemState::Pending(ref mut t) => { - match t.poll(cx) { + match t.poll(lw) { Ok(Async::Ready(v)) => Ok(v), Ok(Async::Pending) => { all_done = false; diff --git a/futures-util/src/future/disabled/select.rs b/futures-util/src/future/disabled/select.rs index b76c2d2572..be267d6677 100644 --- a/futures-util/src/future/disabled/select.rs +++ b/futures-util/src/future/disabled/select.rs @@ -25,10 +25,10 @@ impl Future for Select where A: Future, B: Future { fn poll(&mut self, lw: &LocalWaker) -> Poll { let (mut a, mut b) = self.inner.take().expect("cannot poll Select twice"); - match a.poll(cx) { + match a.poll(lw) { Err(e) => Err(Either::Left((e, b))), Ok(Async::Ready(x)) => Ok(Async::Ready(Either::Left((x, b)))), - Ok(Async::Pending) => match b.poll(cx) { + Ok(Async::Pending) => match b.poll(lw) { Err(e) => Err(Either::Right((e, a))), Ok(Async::Ready(x)) => Ok(Async::Ready(Either::Right((x, a)))), Ok(Async::Pending) => { diff --git a/futures-util/src/future/disabled/select_all.rs b/futures-util/src/future/disabled/select_all.rs index d01fc49480..713ff28e08 100644 --- a/futures-util/src/future/disabled/select_all.rs +++ b/futures-util/src/future/disabled/select_all.rs @@ -51,7 +51,7 @@ impl Future for SelectAll fn poll(&mut self, lw: &LocalWaker) -> Poll { let item = self.inner.iter_mut().enumerate().filter_map(|(i, f)| { - match f.poll(cx) { + match f.poll(lw) { Ok(Async::Pending) => None, Ok(Async::Ready(e)) => Some((i, Ok(e))), Err(e) => Some((i, Err(e))), diff --git a/futures-util/src/future/disabled/select_ok.rs b/futures-util/src/future/disabled/select_ok.rs index 29102036d2..faaa92d8e7 100644 --- a/futures-util/src/future/disabled/select_ok.rs +++ b/futures-util/src/future/disabled/select_ok.rs @@ -49,7 +49,7 @@ impl Future for SelectOk where A: Future { // loop until we've either exhausted all errors, a success was hit, or nothing is ready loop { let item = self.inner.iter_mut().enumerate().filter_map(|(i, f)| { - match f.poll(cx) { + match f.poll(lw) { Ok(Async::Pending) => None, Ok(Async::Ready(e)) => Some((i, Ok(e))), Err(e) => Some((i, Err(e))), diff --git a/futures-util/src/future/flatten.rs b/futures-util/src/future/flatten.rs index 5e468def80..e09124c351 100644 --- a/futures-util/src/future/flatten.rs +++ b/futures-util/src/future/flatten.rs @@ -49,6 +49,6 @@ impl Future for Flatten type Output = ::Output; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.state().poll(cx, |a, ()| a) + self.state().poll(lw, |a, ()| a) } } diff --git a/futures-util/src/future/flatten_stream.rs b/futures-util/src/future/flatten_stream.rs index b0c1063788..b969f55481 100644 --- a/futures-util/src/future/flatten_stream.rs +++ b/futures-util/src/future/flatten_stream.rs @@ -53,7 +53,7 @@ impl Stream for FlattenStream 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 { Pin::new_unchecked(f) }.poll(cx) { + match unsafe { Pin::new_unchecked(f) }.poll(lw) { Poll::Pending => { // State is not changed, early return. return Poll::Pending @@ -69,7 +69,7 @@ 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 { Pin::new_unchecked(s) }.poll_next(cx); + return unsafe { Pin::new_unchecked(s) }.poll_next(lw); } }; diff --git a/futures-util/src/future/fuse.rs b/futures-util/src/future/fuse.rs index 8913f6fe36..b42a31ecce 100644 --- a/futures-util/src/future/fuse.rs +++ b/futures-util/src/future/fuse.rs @@ -34,7 +34,7 @@ impl Future for Fuse { let v = match self.future().as_pin_mut() { Some(fut) => { // safety: this re-pinned future will never move before being dropped - match fut.poll(cx) { + match fut.poll(lw) { Poll::Pending => return Poll::Pending, Poll::Ready(v) => v } diff --git a/futures-util/src/future/inspect.rs b/futures-util/src/future/inspect.rs index 376327019b..5ddcf6520c 100644 --- a/futures-util/src/future/inspect.rs +++ b/futures-util/src/future/inspect.rs @@ -35,7 +35,7 @@ impl Future for Inspect type Output = Fut::Output; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - let e = match self.future().poll(cx) { + let e = match self.future().poll(lw) { 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 a136c90869..06c6824b56 100644 --- a/futures-util/src/future/into_stream.rs +++ b/futures-util/src/future/into_stream.rs @@ -28,7 +28,7 @@ impl Stream for IntoStream { fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let v = match self.future().as_pin_mut() { Some(fut) => { - match fut.poll(cx) { + match fut.poll(lw) { Poll::Pending => return Poll::Pending, Poll::Ready(v) => v } diff --git a/futures-util/src/future/join.rs b/futures-util/src/future/join.rs index 69cc2adaa3..1d03a4d49f 100644 --- a/futures-util/src/future/join.rs +++ b/futures-util/src/future/join.rs @@ -52,7 +52,7 @@ macro_rules! generate { ) -> Poll { let mut all_done = true; $( - if self.$Fut().poll(cx).is_pending() { + if self.$Fut().poll(lw).is_pending() { all_done = false; } )* diff --git a/futures-util/src/future/lazy.rs b/futures-util/src/future/lazy.rs index af0ae7cbec..a249fcbd6d 100644 --- a/futures-util/src/future/lazy.rs +++ b/futures-util/src/future/lazy.rs @@ -47,6 +47,6 @@ impl Future for Lazy type Output = R; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - Poll::Ready((self.f.take().unwrap())(cx)) + Poll::Ready((self.f.take().unwrap())(lw)) } } diff --git a/futures-util/src/future/map.rs b/futures-util/src/future/map.rs index 80e394c597..e47b0fa052 100644 --- a/futures-util/src/future/map.rs +++ b/futures-util/src/future/map.rs @@ -33,7 +33,7 @@ impl Future for Map type Output = T; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - match self.future().poll(cx) { + match self.future().poll(lw) { Poll::Pending => Poll::Pending, Poll::Ready(output) => { let f = self.f().take() diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index 372ea00d3c..8af3aec285 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -88,7 +88,7 @@ impl Future for MaybeDone { let res = unsafe { match Pin::get_mut_unchecked(self.as_mut()) { MaybeDone::Future(a) => { - if let Poll::Ready(res) = Pin::new_unchecked(a).poll(cx) { + if let Poll::Ready(res) = Pin::new_unchecked(a).poll(lw) { res } else { return Poll::Pending diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 262b1891b1..033f84f8f1 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -679,7 +679,7 @@ pub trait FutureExt: Future { fn poll_unpin(&mut self, lw: &LocalWaker) -> Poll where Self: Unpin + Sized { - Pin::new(self).poll(cx) + Pin::new(self).poll(lw) } } diff --git a/futures-util/src/future/option.rs b/futures-util/src/future/option.rs index 470959c855..b538a61469 100644 --- a/futures-util/src/future/option.rs +++ b/futures-util/src/future/option.rs @@ -41,7 +41,7 @@ impl Future for OptionFuture { lw: &LocalWaker ) -> Poll { match self.option().as_pin_mut() { - Some(x) => x.poll(cx).map(Some), + Some(x) => x.poll(lw).map(Some), None => Poll::Ready(None), } } diff --git a/futures-util/src/future/poll_fn.rs b/futures-util/src/future/poll_fn.rs index 555082cc90..50e4690835 100644 --- a/futures-util/src/future/poll_fn.rs +++ b/futures-util/src/future/poll_fn.rs @@ -49,6 +49,6 @@ impl Future for PollFn type Output = T; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - (&mut self.f)(cx) + (&mut self.f)(lw) } } diff --git a/futures-util/src/future/shared.rs b/futures-util/src/future/shared.rs index 2f92a3a94d..78aa58e2f3 100644 --- a/futures-util/src/future/shared.rs +++ b/futures-util/src/future/shared.rs @@ -116,18 +116,18 @@ where return }; if self.waker_key == NULL_WAKER_KEY { - self.waker_key = wakers.insert(Some(cx.waker().clone())); + self.waker_key = wakers.insert(Some(lw.waker().clone())); } else { let waker_slot = &mut wakers[self.waker_key]; let needs_replacement = if let Some(old_waker) = waker_slot { // If there's still an unwoken waker in the slot, only replace // if the current one wouldn't wake the same task. - !old_waker.will_wake(cx.waker()) + !old_waker.will_wake(lw.waker()) } else { true }; if needs_replacement { - *waker_slot = Some(cx.waker().clone()); + *waker_slot = Some(lw.waker().clone()); } } debug_assert!(self.waker_key != NULL_WAKER_KEY); @@ -153,7 +153,7 @@ where fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = &mut *self; - this.set_waker(cx); + this.set_waker(lw); match this.inner.notifier.state.compare_and_swap(IDLE, POLLING, SeqCst) { IDLE => { @@ -173,7 +173,7 @@ where } let waker = local_waker_from_nonlocal(this.inner.notifier.clone()); - let mut cx = cx.with_waker(&waker); + let mut lw = lw.with_waker(&waker); loop { struct Reset<'a>(&'a AtomicUsize); @@ -193,7 +193,7 @@ where // Poll the future let res = unsafe { if let FutureOrOutput::Future(future) = &mut *this.inner.future_or_output.get() { - Pin::new_unchecked(future).poll(&mut cx) + Pin::new_unchecked(future).poll(&mut lw) } else { unreachable!() } diff --git a/futures-util/src/future/then.rs b/futures-util/src/future/then.rs index 6c4aed6db2..1e54a40da5 100644 --- a/futures-util/src/future/then.rs +++ b/futures-util/src/future/then.rs @@ -36,6 +36,6 @@ impl Future for Then type Output = Fut2::Output; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.chain().poll(cx, |output, f| f(output)) + self.chain().poll(lw, |output, f| f(output)) } } diff --git a/futures-util/src/future/unit_error.rs b/futures-util/src/future/unit_error.rs index dcaded4119..6fd6fe1922 100644 --- a/futures-util/src/future/unit_error.rs +++ b/futures-util/src/future/unit_error.rs @@ -30,6 +30,6 @@ impl Future for UnitError type Output = Result; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - self.future().poll(cx).map(Ok) + self.future().poll(lw).map(Ok) } } diff --git a/futures-util/src/future/with_spawner.rs b/futures-util/src/future/with_spawner.rs index dbda11484c..04bf57b4a5 100644 --- a/futures-util/src/future/with_spawner.rs +++ b/futures-util/src/future/with_spawner.rs @@ -32,6 +32,6 @@ impl Future for WithSpawner 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)) + fut.poll(&mut lw.with_spawner(spawner)) } } diff --git a/futures-util/src/io/allow_std.rs b/futures-util/src/io/allow_std.rs index 6c318fddef..12eff3704e 100644 --- a/futures-util/src/io/allow_std.rs +++ b/futures-util/src/io/allow_std.rs @@ -85,7 +85,7 @@ impl AsyncWrite for AllowStdIo where T: io::Write { } fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { - self.poll_flush(cx) + self.poll_flush(lw) } } diff --git a/futures-util/src/io/close.rs b/futures-util/src/io/close.rs index 8c6a1dd220..35482fa889 100644 --- a/futures-util/src/io/close.rs +++ b/futures-util/src/io/close.rs @@ -28,6 +28,6 @@ impl Future for Close<'_, W> { type Output = io::Result<()>; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.writer.poll_close(cx) + self.writer.poll_close(lw) } } diff --git a/futures-util/src/io/copy_into.rs b/futures-util/src/io/copy_into.rs index b0b8ba94db..d0f8def4dc 100644 --- a/futures-util/src/io/copy_into.rs +++ b/futures-util/src/io/copy_into.rs @@ -52,7 +52,7 @@ impl Future for CopyInto<'_, R, W> // If our buffer is empty, then we need to read some data to // continue. if this.pos == this.cap && !this.read_done { - let n = try_ready!(this.reader.poll_read(cx, &mut this.buf)); + let n = try_ready!(this.reader.poll_read(lw, &mut this.buf)); if n == 0 { this.read_done = true; } else { @@ -63,7 +63,7 @@ impl Future for CopyInto<'_, R, W> // If our buffer has some data, let's write it out! while this.pos < this.cap { - let i = try_ready!(this.writer.poll_write(cx, &this.buf[this.pos..this.cap])); + let i = try_ready!(this.writer.poll_write(lw, &this.buf[this.pos..this.cap])); if i == 0 { return Poll::Ready(Err(io::ErrorKind::WriteZero.into())) } else { @@ -76,7 +76,7 @@ impl Future for CopyInto<'_, R, W> // data and finish the transfer. // done with the entire transfer. if this.pos == this.cap && this.read_done { - try_ready!(this.writer.poll_flush(cx)); + try_ready!(this.writer.poll_flush(lw)); return Poll::Ready(Ok(this.amt)); } } diff --git a/futures-util/src/io/flush.rs b/futures-util/src/io/flush.rs index 7527c87b7d..69aa7e0b5e 100644 --- a/futures-util/src/io/flush.rs +++ b/futures-util/src/io/flush.rs @@ -33,6 +33,6 @@ impl Future for Flush<'_, W> type Output = io::Result<()>; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.writer.poll_flush(cx) + self.writer.poll_flush(lw) } } diff --git a/futures-util/src/io/read.rs b/futures-util/src/io/read.rs index f015053cb7..b485dab1be 100644 --- a/futures-util/src/io/read.rs +++ b/futures-util/src/io/read.rs @@ -27,6 +27,6 @@ impl Future for Read<'_, R> { fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = &mut *self; - this.reader.poll_read(cx, this.buf) + this.reader.poll_read(lw, this.buf) } } diff --git a/futures-util/src/io/read_exact.rs b/futures-util/src/io/read_exact.rs index 837e80e614..c9b392efe8 100644 --- a/futures-util/src/io/read_exact.rs +++ b/futures-util/src/io/read_exact.rs @@ -32,7 +32,7 @@ impl Future for ReadExact<'_, R> { fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = &mut *self; while !this.buf.is_empty() { - let n = try_ready!(this.reader.poll_read(cx, this.buf)); + let n = try_ready!(this.reader.poll_read(lw, this.buf)); { let (_, rest) = mem::replace(&mut this.buf, &mut []).split_at_mut(n); this.buf = rest; diff --git a/futures-util/src/io/read_to_end.rs b/futures-util/src/io/read_to_end.rs index 6c76a944bd..288c4adf7f 100644 --- a/futures-util/src/io/read_to_end.rs +++ b/futures-util/src/io/read_to_end.rs @@ -61,7 +61,7 @@ fn read_to_end_internal( } } - match rd.poll_read(cx, &mut g.buf[g.len..]) { + match rd.poll_read(lw, &mut g.buf[g.len..]) { Poll::Ready(Ok(0)) => { ret = Poll::Ready(Ok(())); break; @@ -85,6 +85,6 @@ impl Future for ReadToEnd<'_, A> fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { let this = &mut *self; - read_to_end_internal(this.reader, cx, this.buf) + read_to_end_internal(this.reader, lw, this.buf) } } diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index 81e4f92d42..003360bf6c 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -23,10 +23,10 @@ fn lock_and_then( ) -> Poll> where F: FnOnce(&mut T, &LocalWaker) -> Poll> { - match lock.poll_lock(cx) { + match lock.poll_lock(lw) { // Safety: the value behind the bilock used by `ReadHalf` and `WriteHalf` is never exposed // 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::Ready(mut l) => f(unsafe { Pin::get_mut_unchecked(l.as_pin_mut()) }, lw), Poll::Pending => Poll::Pending, } } @@ -40,13 +40,13 @@ impl AsyncRead for ReadHalf { fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_read(cx, buf)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_read(lw, buf)) } fn poll_vectored_read(&mut self, lw: &LocalWaker, vec: &mut [&mut IoVec]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_read(cx, vec)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_vectored_read(lw, vec)) } } @@ -54,20 +54,20 @@ impl AsyncWrite for WriteHalf { fn poll_write(&mut self, lw: &LocalWaker, buf: &[u8]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_write(cx, buf)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_write(lw, buf)) } fn poll_vectored_write(&mut self, lw: &LocalWaker, vec: &[&IoVec]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_write(cx, vec)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_vectored_write(lw, vec)) } fn poll_flush(&mut self, lw: &LocalWaker) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_flush(cx)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_flush(lw)) } fn poll_close(&mut self, lw: &LocalWaker) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_close(cx)) + lock_and_then(&self.handle, lw, |l, lw| l.poll_close(lw)) } } diff --git a/futures-util/src/io/write_all.rs b/futures-util/src/io/write_all.rs index fd40a6ce91..281fe5b501 100644 --- a/futures-util/src/io/write_all.rs +++ b/futures-util/src/io/write_all.rs @@ -32,7 +32,7 @@ impl Future for WriteAll<'_, W> { fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let this = &mut *self; while !this.buf.is_empty() { - let n = try_ready!(this.writer.poll_write(cx, this.buf)); + let n = try_ready!(this.writer.poll_write(lw, this.buf)); { let (_, rest) = mem::replace(&mut this.buf, &[]).split_at(n); this.buf = rest; diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index d13e9ae2cb..b3d15b2a7a 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -39,7 +39,7 @@ macro_rules! delegate_sink { mut self: Pin<&mut Self>, lw: &mut $crate::core_reexport::task::Context, ) -> $crate::core_reexport::task::Poll> { - self.$field().poll_ready(cx) + self.$field().poll_ready(lw) } fn start_send( @@ -53,14 +53,14 @@ macro_rules! delegate_sink { mut self: Pin<&mut Self>, lw: &mut $crate::core_reexport::task::Context ) -> $crate::core_reexport::task::Poll> { - self.$field().poll_flush(cx) + self.$field().poll_flush(lw) } fn poll_close( mut self: Pin<&mut Self>, lw: &mut $crate::core_reexport::task::Context ) -> $crate::core_reexport::task::Poll> { - self.$field().poll_close(cx) + self.$field().poll_close(lw) } } } diff --git a/futures-util/src/lock.rs b/futures-util/src/lock.rs index 6fa6c3e043..42a7baa353 100644 --- a/futures-util/src/lock.rs +++ b/futures-util/src/lock.rs @@ -104,7 +104,7 @@ impl BiLock { } // type ascription for safety's sake! - let me: Box = Box::new(cx.waker().clone()); + let me: Box = Box::new(lw.waker().clone()); let me = Box::into_raw(me) as usize; match self.arc.state.compare_exchange(1, me, SeqCst, SeqCst) { @@ -270,6 +270,6 @@ impl<'a, T> Future for BiLockAcquire<'a, T> { type Output = BiLockGuard<'a, T>; fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.bilock.poll_lock(cx) + self.bilock.poll_lock(lw) } } diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index 19a50d8e92..0df07b4f52 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -43,13 +43,13 @@ impl Buffer { self: &mut Pin<&mut Self>, lw: &LocalWaker ) -> Poll> { - try_ready!(self.sink().poll_ready(cx)); + try_ready!(self.sink().poll_ready(lw)); while let Some(item) = self.buf().pop_front() { if let Err(e) = self.sink().start_send(item) { return Poll::Ready(Err(e)); } if !self.buf.is_empty() { - try_ready!(self.sink().poll_ready(cx)); + try_ready!(self.sink().poll_ready(lw)); } } Poll::Ready(Ok(())) @@ -61,7 +61,7 @@ impl Stream for Buffer where S: Sink + Stream { type Item = S::Item; fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - self.sink().poll_next(cx) + self.sink().poll_next(lw) } } @@ -74,10 +74,10 @@ impl Sink for Buffer { lw: &LocalWaker, ) -> Poll> { if *self.capacity() == 0 { - return self.sink().poll_ready(cx); + return self.sink().poll_ready(lw); } - if let Poll::Ready(Err(e)) = self.try_empty_buffer(cx) { + if let Poll::Ready(Err(e)) = self.try_empty_buffer(lw) { return Poll::Ready(Err(e)); } @@ -104,17 +104,17 @@ impl Sink for Buffer { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - try_ready!(self.try_empty_buffer(cx)); + try_ready!(self.try_empty_buffer(lw)); debug_assert!(self.buf().is_empty()); - self.sink().poll_flush(cx) + self.sink().poll_flush(lw) } fn poll_close( mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - try_ready!(self.try_empty_buffer(cx)); + try_ready!(self.try_empty_buffer(lw)); debug_assert!(self.buf().is_empty()); - self.sink().poll_close(cx) + self.sink().poll_close(lw) } } diff --git a/futures-util/src/sink/close.rs b/futures-util/src/sink/close.rs index 4e50a40d0d..5793411769 100644 --- a/futures-util/src/sink/close.rs +++ b/futures-util/src/sink/close.rs @@ -28,6 +28,6 @@ impl Future for Close<'_, Si> { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - Pin::new(&mut self.sink).poll_close(cx) + Pin::new(&mut self.sink).poll_close(lw) } } diff --git a/futures-util/src/sink/err_into.rs b/futures-util/src/sink/err_into.rs index c1fce81336..a160f26e08 100644 --- a/futures-util/src/sink/err_into.rs +++ b/futures-util/src/sink/err_into.rs @@ -65,6 +65,6 @@ impl Stream for SinkErrInto mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_next(cx) + self.sink().poll_next(lw) } } diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index 15dd1bc8e0..eb7a39c71b 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -54,8 +54,8 @@ impl Sink for Fanout mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - let sink1_ready = try_poll!(self.sink1().poll_ready(cx)).is_ready(); - let sink2_ready = try_poll!(self.sink2().poll_ready(cx)).is_ready(); + let sink1_ready = try_poll!(self.sink1().poll_ready(lw)).is_ready(); + let sink2_ready = try_poll!(self.sink2().poll_ready(lw)).is_ready(); let ready = sink1_ready && sink2_ready; if ready { Poll::Ready(Ok(())) } else { Poll::Pending } } @@ -73,8 +73,8 @@ impl Sink for Fanout mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - let sink1_ready = try_poll!(self.sink1().poll_flush(cx)).is_ready(); - let sink2_ready = try_poll!(self.sink2().poll_flush(cx)).is_ready(); + let sink1_ready = try_poll!(self.sink1().poll_flush(lw)).is_ready(); + let sink2_ready = try_poll!(self.sink2().poll_flush(lw)).is_ready(); let ready = sink1_ready && sink2_ready; if ready { Poll::Ready(Ok(())) } else { Poll::Pending } } @@ -83,8 +83,8 @@ impl Sink for Fanout mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - let sink1_ready = try_poll!(self.sink1().poll_close(cx)).is_ready(); - let sink2_ready = try_poll!(self.sink2().poll_close(cx)).is_ready(); + let sink1_ready = try_poll!(self.sink1().poll_close(lw)).is_ready(); + let sink2_ready = try_poll!(self.sink2().poll_close(lw)).is_ready(); let ready = sink1_ready && sink2_ready; if ready { Poll::Ready(Ok(())) } else { Poll::Pending } } diff --git a/futures-util/src/sink/flush.rs b/futures-util/src/sink/flush.rs index 8bec004258..5478043363 100644 --- a/futures-util/src/sink/flush.rs +++ b/futures-util/src/sink/flush.rs @@ -34,6 +34,6 @@ impl Future for Flush<'_, Si> { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - Pin::new(&mut self.sink).poll_flush(cx) + Pin::new(&mut self.sink).poll_flush(lw) } } diff --git a/futures-util/src/sink/map_err.rs b/futures-util/src/sink/map_err.rs index 9da7ca0261..6200150749 100644 --- a/futures-util/src/sink/map_err.rs +++ b/futures-util/src/sink/map_err.rs @@ -64,7 +64,7 @@ impl Sink for SinkMapErr lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 - self.sink().poll_ready(cx).map_err(|e| self.take_f()(e)) + self.sink().poll_ready(lw).map_err(|e| self.take_f()(e)) } fn start_send( @@ -80,7 +80,7 @@ impl Sink for SinkMapErr lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 - self.sink().poll_flush(cx).map_err(|e| self.take_f()(e)) + self.sink().poll_flush(lw).map_err(|e| self.take_f()(e)) } fn poll_close( @@ -88,7 +88,7 @@ impl Sink for SinkMapErr lw: &LocalWaker, ) -> Poll> { #[allow(clippy::redundant_closure)] // https://github.com/rust-lang-nursery/rust-clippy/issues/1439 - self.sink().poll_close(cx).map_err(|e| self.take_f()(e)) + self.sink().poll_close(lw).map_err(|e| self.take_f()(e)) } } @@ -99,6 +99,6 @@ impl Stream for SinkMapErr { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_next(cx) + self.sink().poll_next(lw) } } diff --git a/futures-util/src/sink/send.rs b/futures-util/src/sink/send.rs index 4ac438aec4..e7e2708ff3 100644 --- a/futures-util/src/sink/send.rs +++ b/futures-util/src/sink/send.rs @@ -35,7 +35,7 @@ impl Future for Send<'_, Si> { let this = &mut *self; if let Some(item) = this.item.take() { let mut sink = Pin::new(&mut this.sink); - match sink.as_mut().poll_ready(cx) { + match sink.as_mut().poll_ready(lw) { Poll::Ready(Ok(())) => { 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!(Pin::new(&mut this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(lw)); Poll::Ready(Ok(())) } diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index 5cbbb9939e..83eb6158c2 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -49,7 +49,7 @@ where item: Si::SinkItem, ) -> Poll> { debug_assert!(self.buffered.is_none()); - match Pin::new(&mut self.sink).poll_ready(cx) { + match Pin::new(&mut self.sink).poll_ready(lw) { Poll::Ready(Ok(())) => { Poll::Ready(Pin::new(&mut self.sink).start_send(item)) } @@ -77,20 +77,20 @@ where // 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) = this.buffered.take() { - try_ready!(this.try_start_send(cx, item)) + try_ready!(this.try_start_send(lw, item)) } loop { - match this.stream.poll_next_unpin(cx) { + match this.stream.poll_next_unpin(lw) { Poll::Ready(Some(item)) => { - try_ready!(this.try_start_send(cx, item)) + try_ready!(this.try_start_send(lw, item)) } Poll::Ready(None) => { - try_ready!(Pin::new(&mut this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(lw)); return Poll::Ready(Ok(())) } Poll::Pending => { - try_ready!(Pin::new(&mut this.sink).poll_flush(cx)); + try_ready!(Pin::new(&mut this.sink).poll_flush(lw)); return Poll::Pending } } diff --git a/futures-util/src/sink/with.rs b/futures-util/src/sink/with.rs index cfc44a7972..2a69397966 100644 --- a/futures-util/src/sink/with.rs +++ b/futures-util/src/sink/with.rs @@ -90,7 +90,7 @@ impl Stream for With mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_next(cx) + self.sink().poll_next(lw) } } @@ -124,7 +124,7 @@ impl With ) -> Poll> { let buffered = match self.state().as_pin_mut() { State::Empty => return Poll::Ready(Ok(())), - State::Process(fut) => Some(try_ready!(fut.poll(cx))), + State::Process(fut) => Some(try_ready!(fut.poll(lw))), State::Buffered(_) => None, }; if let Some(buffered) = buffered { @@ -151,7 +151,7 @@ impl Sink for With mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.poll(cx) + self.poll(lw) } fn start_send( @@ -167,8 +167,8 @@ impl Sink for With mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - try_ready!(self.poll(cx)); - try_ready!(self.sink().poll_flush(cx)); + try_ready!(self.poll(lw)); + try_ready!(self.sink().poll_flush(lw)); Poll::Ready(Ok(())) } @@ -176,8 +176,8 @@ impl Sink for With mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - try_ready!(self.poll(cx)); - try_ready!(self.sink().poll_close(cx)); + try_ready!(self.poll(lw)); + try_ready!(self.sink().poll_close(lw)); Poll::Ready(Ok(())) } } diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index a3e83d38e1..6e25c55054 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -84,14 +84,14 @@ where let mut stream = unsafe { Pin::new_unchecked(stream) }; if buffer.is_some() { - try_ready!(sink.as_mut().poll_ready(cx)); + try_ready!(sink.as_mut().poll_ready(lw)); let item = buffer.take().unwrap(); try_ready!(Poll::Ready(sink.as_mut().start_send(item))); } if let Some(mut some_stream) = stream.as_mut().as_pin_mut() { - while let Some(x) = ready!(some_stream.as_mut().poll_next(cx)) { + while let Some(x) = ready!(some_stream.as_mut().poll_next(lw)) { let item = try_ready!(Poll::Ready(x)); - match try_poll!(sink.as_mut().poll_ready(cx)) { + match try_poll!(sink.as_mut().poll_ready(lw)) { Poll::Ready(()) => { try_poll!(Poll::Ready(sink.as_mut().start_send(item))) } @@ -118,7 +118,7 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_next(cx) + self.sink().poll_next(lw) } } @@ -135,7 +135,7 @@ where self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.try_empty_stream(cx) + self.try_empty_stream(lw) } fn start_send( @@ -152,9 +152,9 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - match self.as_mut().try_empty_stream(cx) { + match self.as_mut().try_empty_stream(lw) { Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => self.sink().poll_flush(cx), + Poll::Ready(Ok(())) => self.sink().poll_flush(lw), Poll::Ready(Err(e)) => Poll::Ready(Err(e)), } } @@ -163,9 +163,9 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - match self.as_mut().try_empty_stream(cx) { + match self.as_mut().try_empty_stream(lw) { Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => self.sink().poll_close(cx), + Poll::Ready(Ok(())) => self.sink().poll_close(lw), 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 cae2113400..cfb1287ce3 100644 --- a/futures-util/src/stream/buffer_unordered.rs +++ b/futures-util/src/stream/buffer_unordered.rs @@ -113,14 +113,14 @@ where // First up, try to spawn off as many futures as possible by filling up // our slab of futures. while self.in_progress_queue.len() < self.max { - match self.stream().poll_next(cx) { + match self.stream().poll_next(lw) { Poll::Ready(Some(fut)) => self.in_progress_queue().push(fut), Poll::Ready(None) | Poll::Pending => break, } } // Attempt to pull the next value from the in_progress_queue - match Pin::new(self.in_progress_queue()).poll_next(cx) { + match Pin::new(self.in_progress_queue()).poll_next(lw) { 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 3369760858..22c1c10358 100644 --- a/futures-util/src/stream/buffered.rs +++ b/futures-util/src/stream/buffered.rs @@ -109,14 +109,14 @@ where // Try to spawn off as many futures as possible by filling up // our in_progress_queue of futures. while self.in_progress_queue.len() < self.max { - match self.stream().poll_next(cx) { + match self.stream().poll_next(lw) { Poll::Ready(Some(fut)) => self.in_progress_queue().push(fut), Poll::Ready(None) | Poll::Pending => break, } } // Attempt to pull the next value from the in_progress_queue - let res = Pin::new(self.in_progress_queue()).poll_next(cx); + let res = Pin::new(self.in_progress_queue()).poll_next(lw); 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 9861c79847..3d8cfa722b 100644 --- a/futures-util/src/stream/catch_unwind.rs +++ b/futures-util/src/stream/catch_unwind.rs @@ -37,7 +37,7 @@ impl Stream for CatchUnwind Poll::Ready(None) } else { let res = catch_unwind(AssertUnwindSafe(|| { - self.stream().poll_next(cx) + self.stream().poll_next(lw) })); match res { diff --git a/futures-util/src/stream/chain.rs b/futures-util/src/stream/chain.rs index a148e92097..e357c757c7 100644 --- a/futures-util/src/stream/chain.rs +++ b/futures-util/src/stream/chain.rs @@ -41,11 +41,11 @@ where St1: Stream, lw: &LocalWaker, ) -> Poll> { if let Some(first) = self.first().as_pin_mut() { - if let Some(item) = ready!(first.poll_next(cx)) { + if let Some(item) = ready!(first.poll_next(lw)) { return Poll::Ready(Some(item)) } } Pin::set(self.first(), None); - self.second().poll_next(cx) + self.second().poll_next(lw) } } diff --git a/futures-util/src/stream/chunks.rs b/futures-util/src/stream/chunks.rs index b874888c82..52b4e7da50 100644 --- a/futures-util/src/stream/chunks.rs +++ b/futures-util/src/stream/chunks.rs @@ -72,7 +72,7 @@ impl Stream for Chunks { ) -> Poll> { let cap = self.items.capacity(); loop { - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { // Push the item into the buffer and check whether it is full. // If so, replace our buffer with a new and empty one and return // the full one. diff --git a/futures-util/src/stream/collect.rs b/futures-util/src/stream/collect.rs index 46e59bd0b4..74878af581 100644 --- a/futures-util/src/stream/collect.rs +++ b/futures-util/src/stream/collect.rs @@ -43,7 +43,7 @@ where St: Stream, fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { Some(e) => self.collection().extend(Some(e)), None => return Poll::Ready(self.finish()), } diff --git a/futures-util/src/stream/concat.rs b/futures-util/src/stream/concat.rs index 1dbccbc055..7797673fbf 100644 --- a/futures-util/src/stream/concat.rs +++ b/futures-util/src/stream/concat.rs @@ -57,7 +57,7 @@ where St: Stream, mut self: Pin<&mut Self>, lw: &LocalWaker ) -> Poll { loop { - match self.stream().poll_next(cx) { + match self.stream().poll_next(lw) { Poll::Pending => return Poll::Pending, Poll::Ready(None) => { return Poll::Ready(self.accum().take().unwrap_or_default()) diff --git a/futures-util/src/stream/disabled/select_all.rs b/futures-util/src/stream/disabled/select_all.rs index a176bdb1f0..214aafa242 100644 --- a/futures-util/src/stream/disabled/select_all.rs +++ b/futures-util/src/stream/disabled/select_all.rs @@ -71,7 +71,7 @@ impl Stream for SelectAll { &mut self, lw: &LocalWaker, ) -> Poll, Self::Error> { - match self.inner.poll_next(cx).map_err(|(err, _)| err)? { + match self.inner.poll_next(lw).map_err(|(err, _)| err)? { Async::Pending => Ok(Async::Pending), Async::Ready(Some((Some(item), remaining))) => { self.push(remaining); diff --git a/futures-util/src/stream/filter.rs b/futures-util/src/stream/filter.rs index f35e9fdfda..07fffaeae4 100644 --- a/futures-util/src/stream/filter.rs +++ b/futures-util/src/stream/filter.rs @@ -84,7 +84,7 @@ impl Stream for Filter ) -> Poll> { loop { if self.pending_fut().as_pin_mut().is_none() { - let item = match ready!(self.stream().poll_next(cx)) { + let item = match ready!(self.stream().poll_next(lw)) { Some(e) => e, None => return Poll::Ready(None), }; @@ -93,7 +93,7 @@ impl Stream for Filter *self.pending_item() = Some(item); } - let yield_item = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); + let yield_item = ready!(self.pending_fut().as_pin_mut().unwrap().poll(lw)); Pin::set(self.pending_fut(), None); let item = self.pending_item().take().unwrap(); diff --git a/futures-util/src/stream/filter_map.rs b/futures-util/src/stream/filter_map.rs index 48e818eb7c..2520483a54 100644 --- a/futures-util/src/stream/filter_map.rs +++ b/futures-util/src/stream/filter_map.rs @@ -77,7 +77,7 @@ impl Stream for FilterMap ) -> Poll> { loop { if self.pending().as_pin_mut().is_none() { - let item = match ready!(self.stream().poll_next(cx)) { + let item = match ready!(self.stream().poll_next(lw)) { Some(e) => e, None => return Poll::Ready(None), }; @@ -85,7 +85,7 @@ impl Stream for FilterMap Pin::set(self.pending(), Some(fut)); } - let item = ready!(self.pending().as_pin_mut().unwrap().poll(cx)); + let item = ready!(self.pending().as_pin_mut().unwrap().poll(lw)); 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 be52266196..c73d9a58ed 100644 --- a/futures-util/src/stream/flatten.rs +++ b/futures-util/src/stream/flatten.rs @@ -69,12 +69,12 @@ impl Stream for Flatten ) -> Poll> { loop { if self.next().as_pin_mut().is_none() { - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { Some(e) => Pin::set(self.next(), Some(e)), None => return Poll::Ready(None), } } - let item = ready!(self.next().as_pin_mut().unwrap().poll_next(cx)); + let item = ready!(self.next().as_pin_mut().unwrap().poll_next(lw)); if item.is_some() { return Poll::Ready(item); } else { diff --git a/futures-util/src/stream/fold.rs b/futures-util/src/stream/fold.rs index e190b25a82..0fbf7e2a3a 100644 --- a/futures-util/src/stream/fold.rs +++ b/futures-util/src/stream/fold.rs @@ -50,12 +50,12 @@ impl Future for Fold 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)); + let accum = ready!(self.future().as_pin_mut().unwrap().poll(lw)); *self.accum() = Some(accum); Pin::set(self.future(), None); } - let item = ready!(self.stream().poll_next(cx)); + let item = ready!(self.stream().poll_next(lw)); let accum = self.accum().take() .expect("Fold polled after completion"); diff --git a/futures-util/src/stream/for_each.rs b/futures-util/src/stream/for_each.rs index b70914df96..c853e678f9 100644 --- a/futures-util/src/stream/for_each.rs +++ b/futures-util/src/stream/for_each.rs @@ -51,11 +51,11 @@ impl Future for ForEach fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { loop { if let Some(future) = self.future().as_pin_mut() { - ready!(future.poll(cx)); + ready!(future.poll(lw)); } Pin::set(self.future(), None); - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { Some(e) => { let future = (self.f())(e); Pin::set(self.future(), Some(future)); diff --git a/futures-util/src/stream/for_each_concurrent.rs b/futures-util/src/stream/for_each_concurrent.rs index abc23a7512..477419a2ce 100644 --- a/futures-util/src/stream/for_each_concurrent.rs +++ b/futures-util/src/stream/for_each_concurrent.rs @@ -65,7 +65,7 @@ impl Future for ForEachConcurrent if self.limit().map(|limit| limit.get() > current_len).unwrap_or(true) { let mut stream_completed = false; let elem = if let Some(stream) = self.stream().as_pin_mut() { - match stream.poll_next(cx) { + match stream.poll_next(lw) { Poll::Ready(Some(elem)) => { made_progress_this_iter = true; Some(elem) @@ -88,7 +88,7 @@ impl Future for ForEachConcurrent } } - match self.futures().poll_next_unpin(cx) { + match self.futures().poll_next_unpin(lw) { Poll::Ready(Some(())) => made_progress_this_iter = true, Poll::Ready(None) => { if self.stream().is_none() { diff --git a/futures-util/src/stream/forward.rs b/futures-util/src/stream/forward.rs index 963c891928..bd741f4d28 100644 --- a/futures-util/src/stream/forward.rs +++ b/futures-util/src/stream/forward.rs @@ -52,7 +52,7 @@ where debug_assert!(self.buffered_item.is_none()); { let mut sink = self.sink().as_pin_mut().unwrap(); - if try_poll!(sink.as_mut().poll_ready(cx)).is_ready() { + if try_poll!(sink.as_mut().poll_ready(lw)).is_ready() { return Poll::Ready(sink.start_send(item)); } } @@ -75,22 +75,22 @@ where // 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.as_mut().try_start_send(cx, item)); + try_ready!(self.as_mut().try_start_send(lw, item)); } loop { - match self.stream().poll_next(cx) { + match self.stream().poll_next(lw) { Poll::Ready(Some(Ok(item))) => - try_ready!(self.as_mut().try_start_send(cx, item)), + try_ready!(self.as_mut().try_start_send(lw, item)), Poll::Ready(Some(Err(e))) => return Poll::Ready(Err(e)), Poll::Ready(None) => { try_ready!(self.sink().as_pin_mut().expect(INVALID_POLL) - .poll_close(cx)); + .poll_close(lw)); return Poll::Ready(Ok(self.sink().take().unwrap())) } Poll::Pending => { try_ready!(self.sink().as_pin_mut().expect(INVALID_POLL) - .poll_flush(cx)); + .poll_flush(lw)); return Poll::Pending } } diff --git a/futures-util/src/stream/fuse.rs b/futures-util/src/stream/fuse.rs index b59aa7abb2..b6b03481bd 100644 --- a/futures-util/src/stream/fuse.rs +++ b/futures-util/src/stream/fuse.rs @@ -81,7 +81,7 @@ impl Stream for Fuse { return Poll::Ready(None); } - let item = ready!(self.stream().poll_next(cx)); + let item = ready!(self.stream().poll_next(lw)); if item.is_none() { *self.done() = true; } diff --git a/futures-util/src/stream/futures_ordered.rs b/futures-util/src/stream/futures_ordered.rs index 1b43ae32f5..33f24c8b2f 100644 --- a/futures-util/src/stream/futures_ordered.rs +++ b/futures-util/src/stream/futures_ordered.rs @@ -51,7 +51,7 @@ impl Future for OrderWrapper mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - self.data().poll(cx) + self.data().poll(lw) .map(|output| OrderWrapper { data: output, index: self.index }) } } @@ -185,7 +185,7 @@ impl Stream for FuturesOrdered { } loop { - match Pin::new(&mut this.in_progress_queue).poll_next(cx) { + match Pin::new(&mut this.in_progress_queue).poll_next(lw) { 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/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index d36a97ac72..194f5b52d2 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -258,7 +258,7 @@ impl Stream for FuturesUnordered { -> Poll> { // Ensure `parent` is correctly set. - self.ready_to_run_queue.waker.register(cx.waker()); + self.ready_to_run_queue.waker.register(lw.waker()); loop { // Safety: &mut self guarantees the mutual exclusion `dequeue` @@ -275,7 +275,7 @@ impl Stream for FuturesUnordered { // At this point, it may be worth yielding the thread & // spinning a few times... but for now, just yield using the // task system. - cx.local_waker().wake(); + lw.local_waker().wake(); return Poll::Pending; } Dequeue::Data(task) => task, @@ -367,12 +367,12 @@ impl Stream for FuturesUnordered { // deallocating the task if need be. let res = { let local_waker = bomb.task.as_ref().unwrap().local_waker(); - let mut cx = cx.with_waker(&*local_waker); + let mut lw = lw.with_waker(&*local_waker); // Safety: We won't move the future ever again let future = unsafe { Pin::new_unchecked(future) }; - future.poll(&mut cx) + future.poll(&mut lw) }; match res { diff --git a/futures-util/src/stream/inspect.rs b/futures-util/src/stream/inspect.rs index 1f488eb158..f845df7844 100644 --- a/futures-util/src/stream/inspect.rs +++ b/futures-util/src/stream/inspect.rs @@ -61,7 +61,7 @@ impl Stream for Inspect mut self: Pin<&mut Self>, lw: &LocalWaker ) -> Poll> { - let item = ready!(self.stream().poll_next(cx)); + let item = ready!(self.stream().poll_next(lw)); Poll::Ready(item.map(|e| { (self.f())(&e); e diff --git a/futures-util/src/stream/into_future.rs b/futures-util/src/stream/into_future.rs index a41095fab4..9337ac7a7c 100644 --- a/futures-util/src/stream/into_future.rs +++ b/futures-util/src/stream/into_future.rs @@ -67,7 +67,7 @@ impl Future for StreamFuture { ) -> Poll { let item = { let s = self.stream.as_mut().expect("polling StreamFuture twice"); - ready!(Pin::new(s).poll_next(cx)) + ready!(Pin::new(s).poll_next(lw)) }; let stream = self.stream.take().unwrap(); Poll::Ready((item, stream)) diff --git a/futures-util/src/stream/map.rs b/futures-util/src/stream/map.rs index 3e96d07a20..84be4152ef 100644 --- a/futures-util/src/stream/map.rs +++ b/futures-util/src/stream/map.rs @@ -62,7 +62,7 @@ impl Stream for Map mut self: Pin<&mut Self>, lw: &LocalWaker ) -> Poll> { - let option = ready!(self.stream().poll_next(cx)); + let option = ready!(self.stream().poll_next(lw)); Poll::Ready(option.map(self.f())) } } diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index e13eeae1a5..e98bc7aa44 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -1036,6 +1036,6 @@ pub trait StreamExt: Stream { ) -> Poll> where Self: Unpin + Sized { - Pin::new(self).poll_next(cx) + Pin::new(self).poll_next(lw) } } diff --git a/futures-util/src/stream/next.rs b/futures-util/src/stream/next.rs index 4c0e4fa84a..662d64959b 100644 --- a/futures-util/src/stream/next.rs +++ b/futures-util/src/stream/next.rs @@ -26,6 +26,6 @@ impl Future for Next<'_, St> { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - Pin::new(&mut *self.stream).poll_next(cx) + Pin::new(&mut *self.stream).poll_next(lw) } } diff --git a/futures-util/src/stream/once.rs b/futures-util/src/stream/once.rs index e66e202359..737828d945 100644 --- a/futures-util/src/stream/once.rs +++ b/futures-util/src/stream/once.rs @@ -43,7 +43,7 @@ impl Stream for Once { lw: &LocalWaker, ) -> Poll> { let val = if let Some(f) = self.future().as_pin_mut() { - ready!(f.poll(cx)) + ready!(f.poll(lw)) } else { return Poll::Ready(None) }; diff --git a/futures-util/src/stream/peek.rs b/futures-util/src/stream/peek.rs index 18f003b09d..40f711d0da 100644 --- a/futures-util/src/stream/peek.rs +++ b/futures-util/src/stream/peek.rs @@ -41,7 +41,7 @@ impl Peekable { if self.peeked().is_some() { return Poll::Ready(self.peeked().as_ref()) } - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { None => Poll::Ready(None), Some(item) => { *self.peeked() = Some(item); @@ -61,7 +61,7 @@ impl Stream for Peekable { if let Some(item) = self.peeked().take() { return Poll::Ready(Some(item)) } - self.stream().poll_next(cx) + self.stream().poll_next(lw) } } diff --git a/futures-util/src/stream/poll_fn.rs b/futures-util/src/stream/poll_fn.rs index 05f32a8004..7b0588beb3 100644 --- a/futures-util/src/stream/poll_fn.rs +++ b/futures-util/src/stream/poll_fn.rs @@ -49,6 +49,6 @@ where type Item = T; fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - (&mut self.f)(cx) + (&mut self.f)(lw) } } diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index e53b7a5ecb..d00072d371 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -52,9 +52,9 @@ impl Stream for Select let stream2 = unsafe { Pin::new_unchecked(stream2) }; if *flag { - poll_inner(flag, stream1, stream2, cx) + poll_inner(flag, stream1, stream2, lw) } else { - poll_inner(flag, stream2, stream1, cx) + poll_inner(flag, stream2, stream1, lw) } } } @@ -67,13 +67,13 @@ fn poll_inner( ) -> Poll> where St1: Stream, St2: Stream { - let a_done = match a.poll_next(cx) { + let a_done = match a.poll_next(lw) { Poll::Ready(Some(item)) => return Poll::Ready(Some(item)), Poll::Ready(None) => true, Poll::Pending => false, }; - match b.poll_next(cx) { + match b.poll_next(lw) { Poll::Ready(Some(item)) => { // If the other stream isn't finished yet, give them a chance to // go first next time as we pulled something off `b`. diff --git a/futures-util/src/stream/skip.rs b/futures-util/src/stream/skip.rs index 95e1c3a270..9414b362fe 100644 --- a/futures-util/src/stream/skip.rs +++ b/futures-util/src/stream/skip.rs @@ -59,13 +59,13 @@ impl Stream for Skip { lw: &LocalWaker, ) -> Poll> { while *self.remaining() > 0 { - match ready!(self.stream().poll_next(cx)) { + match ready!(self.stream().poll_next(lw)) { Some(_) => *self.remaining() -= 1, None => return Poll::Ready(None), } } - self.stream().poll_next(cx) + self.stream().poll_next(lw) } } diff --git a/futures-util/src/stream/skip_while.rs b/futures-util/src/stream/skip_while.rs index 0166c4201a..01ae7eb41b 100644 --- a/futures-util/src/stream/skip_while.rs +++ b/futures-util/src/stream/skip_while.rs @@ -78,12 +78,12 @@ impl Stream for SkipWhile lw: &LocalWaker, ) -> Poll> { if *self.done_skipping() { - return self.stream().poll_next(cx); + return self.stream().poll_next(lw); } loop { if self.pending_item().is_none() { - let item = match ready!(self.stream().poll_next(cx)) { + let item = match ready!(self.stream().poll_next(lw)) { Some(e) => e, None => return Poll::Ready(None), }; @@ -92,7 +92,7 @@ impl Stream for SkipWhile *self.pending_item() = Some(item); } - let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); + let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().poll(lw)); let item = self.pending_item().take().unwrap(); Pin::set(self.pending_fut(), None); diff --git a/futures-util/src/stream/split.rs b/futures-util/src/stream/split.rs index 67e994f97e..079027c71c 100644 --- a/futures-util/src/stream/split.rs +++ b/futures-util/src/stream/split.rs @@ -29,8 +29,8 @@ impl Stream for SplitStream { type Item = S::Item; fn poll_next(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { - match self.0.poll_lock(cx) { - Poll::Ready(mut inner) => inner.as_pin_mut().poll_next(cx), + match self.0.poll_lock(lw) { + Poll::Ready(mut inner) => inner.as_pin_mut().poll_next(lw), Poll::Pending => Poll::Pending, } } @@ -73,7 +73,7 @@ impl Sink for SplitSink { if self.slot.is_none() { return Poll::Ready(Ok(())); } - try_ready!(self.as_mut().poll_flush(cx)); + try_ready!(self.as_mut().poll_flush(lw)); } } @@ -84,15 +84,15 @@ impl Sink for SplitSink { fn poll_flush(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let this = &mut *self; - match this.lock.poll_lock(cx) { + match this.lock.poll_lock(lw) { Poll::Ready(mut inner) => { if this.slot.is_some() { - try_ready!(inner.as_pin_mut().poll_ready(cx)); + try_ready!(inner.as_pin_mut().poll_ready(lw)); if let Err(e) = inner.as_pin_mut().start_send(this.slot.take().unwrap()) { return Poll::Ready(Err(e)); } } - inner.as_pin_mut().poll_flush(cx) + inner.as_pin_mut().poll_flush(lw) } Poll::Pending => Poll::Pending, } @@ -100,15 +100,15 @@ impl Sink for SplitSink { fn poll_close(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { let this = &mut *self; - match this.lock.poll_lock(cx) { + match this.lock.poll_lock(lw) { Poll::Ready(mut inner) => { if this.slot.is_some() { - try_ready!(inner.as_pin_mut().poll_ready(cx)); + try_ready!(inner.as_pin_mut().poll_ready(lw)); if let Err(e) = inner.as_pin_mut().start_send(this.slot.take().unwrap()) { return Poll::Ready(Err(e)); } } - inner.as_pin_mut().poll_close(cx) + inner.as_pin_mut().poll_close(lw) } Poll::Pending => Poll::Pending, } diff --git a/futures-util/src/stream/take.rs b/futures-util/src/stream/take.rs index 28bbc6ff10..c3db35adbf 100644 --- a/futures-util/src/stream/take.rs +++ b/futures-util/src/stream/take.rs @@ -63,7 +63,7 @@ impl Stream for Take if *self.remaining() == 0 { Poll::Ready(None) } else { - let next = ready!(self.stream().poll_next(cx)); + let next = ready!(self.stream().poll_next(lw)); match next { Some(_) => *self.remaining() -= 1, None => *self.remaining() = 0, diff --git a/futures-util/src/stream/take_while.rs b/futures-util/src/stream/take_while.rs index 2f2de43d62..c21f3afd1b 100644 --- a/futures-util/src/stream/take_while.rs +++ b/futures-util/src/stream/take_while.rs @@ -82,7 +82,7 @@ impl Stream for TakeWhile } if self.pending_item().is_none() { - let item = match ready!(self.stream().poll_next(cx)) { + let item = match ready!(self.stream().poll_next(lw)) { Some(e) => e, None => return Poll::Ready(None), }; @@ -91,7 +91,7 @@ impl Stream for TakeWhile *self.pending_item() = Some(item); } - let take = ready!(self.pending_fut().as_pin_mut().unwrap().poll(cx)); + let take = ready!(self.pending_fut().as_pin_mut().unwrap().poll(lw)); Pin::set(self.pending_fut(), None); let item = self.pending_item().take().unwrap(); diff --git a/futures-util/src/stream/then.rs b/futures-util/src/stream/then.rs index 34482d4bbf..fbcd4c966c 100644 --- a/futures-util/src/stream/then.rs +++ b/futures-util/src/stream/then.rs @@ -48,7 +48,7 @@ impl Stream for Then lw: &LocalWaker ) -> Poll> { if self.future().as_pin_mut().is_none() { - let item = match ready!(self.stream().poll_next(cx)) { + let item = match ready!(self.stream().poll_next(lw)) { None => return Poll::Ready(None), Some(e) => e, }; @@ -56,7 +56,7 @@ impl Stream for Then Pin::set(self.future(), Some(fut)); } - let e = ready!(self.future().as_pin_mut().unwrap().poll(cx)); + let e = ready!(self.future().as_pin_mut().unwrap().poll(lw)); 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 d5aab6570a..a619b9c406 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -93,7 +93,7 @@ impl Stream for Unfold Pin::set(self.fut(), Some(fut)); } - let step = ready!(self.fut().as_pin_mut().unwrap().poll(cx)); + let step = ready!(self.fut().as_pin_mut().unwrap().poll(lw)); Pin::set(self.fut(), None); if let Some((item, next_state)) = step { diff --git a/futures-util/src/stream/zip.rs b/futures-util/src/stream/zip.rs index 650bc12fcb..5825ce611c 100644 --- a/futures-util/src/stream/zip.rs +++ b/futures-util/src/stream/zip.rs @@ -47,13 +47,13 @@ impl Stream for Zip lw: &LocalWaker ) -> Poll> { if self.queued1().is_none() { - match self.stream1().poll_next(cx) { + match self.stream1().poll_next(lw) { Poll::Ready(Some(item1)) => *self.queued1() = Some(item1), Poll::Ready(None) | Poll::Pending => {} } } if self.queued2().is_none() { - match self.stream2().poll_next(cx) { + match self.stream2().poll_next(lw) { Poll::Ready(Some(item2)) => *self.queued2() = Some(item2), Poll::Ready(None) | Poll::Pending => {} } diff --git a/futures-util/src/task/atomic_waker.rs b/futures-util/src/task/atomic_waker.rs index 73e64273b1..d1dc684c5e 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-util/src/task/atomic_waker.rs @@ -187,7 +187,7 @@ impl AtomicWaker { /// fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { /// // Register **before** checking `set` to avoid a race condition /// // that would result in lost notifications. - /// self.waker.register(cx.waker()); + /// self.waker.register(lw.waker()); /// /// if self.set.load(SeqCst) { /// Poll::Ready(()) diff --git a/futures-util/src/task/spawn/spawn_with_handle.rs b/futures-util/src/task/spawn/spawn_with_handle.rs index d1580a8a31..53d15aaa47 100644 --- a/futures-util/src/task/spawn/spawn_with_handle.rs +++ b/futures-util/src/task/spawn/spawn_with_handle.rs @@ -34,7 +34,7 @@ impl Future for JoinHandle { type Output = T; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - match self.rx.poll_unpin(cx) { + match self.rx.poll_unpin(lw) { Poll::Ready(Ok(Ok(output))) => Poll::Ready(output), Poll::Ready(Ok(Err(e))) => panic::resume_unwind(e), Poll::Ready(Err(e)) => panic::resume_unwind(Box::new(e)), @@ -61,14 +61,14 @@ impl Future for Wrapped { type Output = (); fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { - if let Poll::Ready(_) = self.tx().as_mut().unwrap().poll_cancel(cx) { + if let Poll::Ready(_) = self.tx().as_mut().unwrap().poll_cancel(lw) { if !self.keep_running().load(Ordering::SeqCst) { // Cancelled, bail out return Poll::Ready(()) } } - let output = match self.future().poll(cx) { + let output = match self.future().poll(lw) { Poll::Ready(output) => output, Poll::Pending => return Poll::Pending, }; diff --git a/futures-util/src/try_future/and_then.rs b/futures-util/src/try_future/and_then.rs index 0bfeb3b47b..47b061ee1f 100644 --- a/futures-util/src/try_future/and_then.rs +++ b/futures-util/src/try_future/and_then.rs @@ -33,7 +33,7 @@ impl Future for AndThen type Output = Result; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.try_chain().poll(cx, |result, async_op| { + self.try_chain().poll(lw, |result, async_op| { match result { Ok(ok) => TryChainAction::Future(async_op(ok)), Err(err) => TryChainAction::Output(Err(err)), diff --git a/futures-util/src/try_future/err_into.rs b/futures-util/src/try_future/err_into.rs index cdbd917028..95f3d70505 100644 --- a/futures-util/src/try_future/err_into.rs +++ b/futures-util/src/try_future/err_into.rs @@ -35,7 +35,7 @@ impl Future for ErrInto mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - self.future().try_poll(cx) + self.future().try_poll(lw) .map(|res| res.map_err(Into::into)) } } diff --git a/futures-util/src/try_future/flatten_sink.rs b/futures-util/src/try_future/flatten_sink.rs index 719214ca23..2a04367144 100644 --- a/futures-util/src/try_future/flatten_sink.rs +++ b/futures-util/src/try_future/flatten_sink.rs @@ -55,13 +55,13 @@ where lw: &LocalWaker, ) -> Poll> { let resolved_stream = match self.as_mut().project_pin() { - Ready(s) => return s.poll_ready(cx), - Waiting(f) => try_ready!(f.try_poll(cx)), + Ready(s) => return s.poll_ready(lw), + Waiting(f) => try_ready!(f.try_poll(lw)), Closed => panic!("poll_ready called after eof"), }; Pin::set(self.as_mut(), FlattenSink(Ready(resolved_stream))); if let Ready(resolved_stream) = self.project_pin() { - resolved_stream.poll_ready(cx) + resolved_stream.poll_ready(lw) } else { unreachable!() } @@ -83,7 +83,7 @@ where lw: &LocalWaker, ) -> Poll> { match self.project_pin() { - Ready(s) => s.poll_flush(cx), + Ready(s) => s.poll_flush(lw), // if sink not yet resolved, nothing written ==> everything flushed Waiting(_) => Poll::Ready(Ok(())), Closed => panic!("poll_flush called after eof"), @@ -95,7 +95,7 @@ where lw: &LocalWaker, ) -> Poll> { let res = match self.as_mut().project_pin() { - Ready(s) => s.poll_close(cx), + Ready(s) => s.poll_close(lw), Waiting(_) | Closed => Poll::Ready(Ok(())), }; if res.is_ready() { diff --git a/futures-util/src/try_future/into_future.rs b/futures-util/src/try_future/into_future.rs index 5b80dc61bb..23c72059d5 100644 --- a/futures-util/src/try_future/into_future.rs +++ b/futures-util/src/try_future/into_future.rs @@ -27,6 +27,6 @@ impl Future for IntoFuture { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - self.future().try_poll(cx) + self.future().try_poll(lw) } } diff --git a/futures-util/src/try_future/map_err.rs b/futures-util/src/try_future/map_err.rs index ade244e24d..a86c5111c9 100644 --- a/futures-util/src/try_future/map_err.rs +++ b/futures-util/src/try_future/map_err.rs @@ -34,7 +34,7 @@ impl Future for MapErr mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - match self.future().try_poll(cx) { + match self.future().try_poll(lw) { Poll::Pending => Poll::Pending, Poll::Ready(result) => { let f = self.f().take() diff --git a/futures-util/src/try_future/map_ok.rs b/futures-util/src/try_future/map_ok.rs index 9eb63e0fef..719aae2aad 100644 --- a/futures-util/src/try_future/map_ok.rs +++ b/futures-util/src/try_future/map_ok.rs @@ -34,7 +34,7 @@ impl Future for MapOk mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - match self.future().try_poll(cx) { + match self.future().try_poll(lw) { Poll::Pending => Poll::Pending, Poll::Ready(result) => { let op = self.f().take() diff --git a/futures-util/src/try_future/or_else.rs b/futures-util/src/try_future/or_else.rs index 4ae9e48c22..6629745172 100644 --- a/futures-util/src/try_future/or_else.rs +++ b/futures-util/src/try_future/or_else.rs @@ -36,7 +36,7 @@ impl Future for OrElse mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - self.try_chain().poll(cx, |result, async_op| { + self.try_chain().poll(lw, |result, async_op| { match result { Ok(ok) => TryChainAction::Output(Ok(ok)), Err(err) => TryChainAction::Future(async_op(err)), diff --git a/futures-util/src/try_future/try_chain.rs b/futures-util/src/try_future/try_chain.rs index a424d8b6fd..77f52a9f96 100644 --- a/futures-util/src/try_future/try_chain.rs +++ b/futures-util/src/try_future/try_chain.rs @@ -41,14 +41,14 @@ impl TryChain let (output, data) = match this { TryChain::First(fut1, data) => { // Poll the first future - match unsafe { Pin::new_unchecked(fut1) }.try_poll(cx) { + match unsafe { Pin::new_unchecked(fut1) }.try_poll(lw) { Poll::Pending => return Poll::Pending, Poll::Ready(output) => (output, data.take().unwrap()), } } TryChain::Second(fut2) => { // Poll the second future - return unsafe { Pin::new_unchecked(fut2) }.try_poll(cx) + return unsafe { Pin::new_unchecked(fut2) }.try_poll(lw) } 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 bebe0d6c9e..d1ada08cc8 100644 --- a/futures-util/src/try_future/try_join.rs +++ b/futures-util/src/try_future/try_join.rs @@ -73,14 +73,14 @@ macro_rules! generate { mut self: Pin<&mut Self>, lw: &LocalWaker ) -> Poll { let mut all_done = true; - if self.Fut1().poll(cx).is_pending() { + if self.Fut1().poll(lw).is_pending() { all_done = false; } else if self.Fut1().output_mut().unwrap().is_err() { return Poll::Ready(Err( self.Fut1().take_output().unwrap().err().unwrap())); } $( - if self.$Fut().poll(cx).is_pending() { + if self.$Fut().poll(lw).is_pending() { all_done = false; } else if self.$Fut().output_mut().unwrap().is_err() { return Poll::Ready(Err( diff --git a/futures-util/src/try_future/unwrap_or_else.rs b/futures-util/src/try_future/unwrap_or_else.rs index bc01ad5d19..7f612d4221 100644 --- a/futures-util/src/try_future/unwrap_or_else.rs +++ b/futures-util/src/try_future/unwrap_or_else.rs @@ -35,7 +35,7 @@ impl Future for UnwrapOrElse mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - match self.future().try_poll(cx) { + match self.future().try_poll(lw) { Poll::Pending => Poll::Pending, Poll::Ready(result) => { let op = self.f().take() diff --git a/futures-util/src/try_stream/err_into.rs b/futures-util/src/try_stream/err_into.rs index 7c35e2f622..aadd27b507 100644 --- a/futures-util/src/try_stream/err_into.rs +++ b/futures-util/src/try_stream/err_into.rs @@ -33,7 +33,7 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.stream().try_poll_next(cx) + self.stream().try_poll_next(lw) .map(|res| res.map(|some| some.map_err(Into::into))) } } diff --git a/futures-util/src/try_stream/into_stream.rs b/futures-util/src/try_stream/into_stream.rs index 2dfc5229e3..33efb03ce2 100644 --- a/futures-util/src/try_stream/into_stream.rs +++ b/futures-util/src/try_stream/into_stream.rs @@ -44,6 +44,6 @@ impl Stream for IntoStream { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.stream().try_poll_next(cx) + self.stream().try_poll_next(lw) } } diff --git a/futures-util/src/try_stream/map_err.rs b/futures-util/src/try_stream/map_err.rs index faa5745322..89cdad0759 100644 --- a/futures-util/src/try_stream/map_err.rs +++ b/futures-util/src/try_stream/map_err.rs @@ -36,7 +36,7 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - match self.stream().try_poll_next(cx) { + match self.stream().try_poll_next(lw) { Poll::Pending => Poll::Pending, Poll::Ready(opt) => Poll::Ready(opt.map(|res| res.map_err(|e| self.f()(e)))), diff --git a/futures-util/src/try_stream/map_ok.rs b/futures-util/src/try_stream/map_ok.rs index f90e53a101..465f7ac3bf 100644 --- a/futures-util/src/try_stream/map_ok.rs +++ b/futures-util/src/try_stream/map_ok.rs @@ -36,7 +36,7 @@ where mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - match self.stream().try_poll_next(cx) { + match self.stream().try_poll_next(lw) { Poll::Pending => Poll::Pending, Poll::Ready(opt) => Poll::Ready(opt.map(|res| res.map(|x| self.f()(x)))), diff --git a/futures-util/src/try_stream/try_buffer_unordered.rs b/futures-util/src/try_stream/try_buffer_unordered.rs index 9db7e3abac..8a769e9ac7 100644 --- a/futures-util/src/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/try_stream/try_buffer_unordered.rs @@ -76,7 +76,7 @@ impl Stream for TryBufferUnordered // First up, try to spawn off as many futures as possible by filling up // our slab of futures. Propagate errors from the stream immediately. while self.in_progress_queue.len() < self.max { - match self.stream().poll_next(cx) { + match self.stream().poll_next(lw) { Poll::Ready(Some(Ok(fut))) => self.in_progress_queue().push(fut.into_future()), Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))), Poll::Ready(None) | Poll::Pending => break, @@ -84,7 +84,7 @@ impl Stream for TryBufferUnordered } // Attempt to pull the next value from the in_progress_queue - match Pin::new(self.in_progress_queue()).poll_next(cx) { + match Pin::new(self.in_progress_queue()).poll_next(lw) { 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 32704356e1..74260fdc34 100644 --- a/futures-util/src/try_stream/try_collect.rs +++ b/futures-util/src/try_stream/try_collect.rs @@ -45,7 +45,7 @@ impl Future for TryCollect lw: &LocalWaker, ) -> Poll { loop { - match ready!(self.stream().try_poll_next(cx)) { + match ready!(self.stream().try_poll_next(lw)) { Some(Ok(x)) => self.items().extend(Some(x)), Some(Err(e)) => return Poll::Ready(Err(e)), None => return Poll::Ready(Ok(self.finish())), diff --git a/futures-util/src/try_stream/try_filter_map.rs b/futures-util/src/try_stream/try_filter_map.rs index 3f96df5e12..5c70a61062 100644 --- a/futures-util/src/try_stream/try_filter_map.rs +++ b/futures-util/src/try_stream/try_filter_map.rs @@ -68,7 +68,7 @@ impl Stream for TryFilterMap ) -> Poll>> { loop { if self.pending().as_pin_mut().is_none() { - let item = match ready!(self.stream().try_poll_next(cx)) { + let item = match ready!(self.stream().try_poll_next(lw)) { Some(Ok(x)) => x, Some(Err(e)) => return Poll::Ready(Some(Err(e))), None => return Poll::Ready(None), @@ -77,7 +77,7 @@ impl Stream for TryFilterMap Pin::set(self.pending(), Some(fut)); } - let result = ready!(self.pending().as_pin_mut().unwrap().try_poll(cx)); + let result = ready!(self.pending().as_pin_mut().unwrap().try_poll(lw)); Pin::set(self.pending(), None); match result { Ok(Some(x)) => return Poll::Ready(Some(Ok(x))), diff --git a/futures-util/src/try_stream/try_fold.rs b/futures-util/src/try_stream/try_fold.rs index 1f8600f9a5..dd52e0ec15 100644 --- a/futures-util/src/try_stream/try_fold.rs +++ b/futures-util/src/try_stream/try_fold.rs @@ -48,12 +48,12 @@ impl Future for TryFold 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)?); + let accum = ready!(self.future().as_pin_mut().unwrap().try_poll(lw)?); *self.accum() = Some(accum); Pin::set(self.future(), None); } - let item = ready!(self.stream().try_poll_next(cx)?); + let item = ready!(self.stream().try_poll_next(lw)?); let accum = self.accum().take() .expect("TryFold polled after completion"); diff --git a/futures-util/src/try_stream/try_for_each.rs b/futures-util/src/try_stream/try_for_each.rs index 3400dc8131..5a06308ce8 100644 --- a/futures-util/src/try_stream/try_for_each.rs +++ b/futures-util/src/try_stream/try_for_each.rs @@ -47,11 +47,11 @@ impl Future for TryForEach fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { loop { if let Some(future) = self.future().as_pin_mut() { - try_ready!(future.try_poll(cx)); + try_ready!(future.try_poll(lw)); } Pin::set(self.future(), None); - match ready!(self.stream().try_poll_next(cx)) { + match ready!(self.stream().try_poll_next(lw)) { Some(Ok(e)) => { let future = (self.f())(e); Pin::set(self.future(), Some(future)); 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 b5b4cb20d7..82200a4137 100644 --- a/futures-util/src/try_stream/try_for_each_concurrent.rs +++ b/futures-util/src/try_stream/try_for_each_concurrent.rs @@ -65,7 +65,7 @@ impl Future for TryForEachConcurrent if self.limit().map(|limit| limit.get() > current_len).unwrap_or(true) { let mut stream_completed = false; let elem = if let Some(stream) = self.stream().as_pin_mut() { - match stream.try_poll_next(cx)? { + match stream.try_poll_next(lw)? { Poll::Ready(Some(elem)) => { made_progress_this_iter = true; Some(elem) @@ -88,7 +88,7 @@ impl Future for TryForEachConcurrent } } - match self.futures().poll_next_unpin(cx)? { + match self.futures().poll_next_unpin(lw)? { Poll::Ready(Some(())) => made_progress_this_iter = true, Poll::Ready(None) => { if self.stream().is_none() { diff --git a/futures-util/src/try_stream/try_next.rs b/futures-util/src/try_stream/try_next.rs index 9473daa280..a6b21b0093 100644 --- a/futures-util/src/try_stream/try_next.rs +++ b/futures-util/src/try_stream/try_next.rs @@ -28,7 +28,7 @@ impl Future for TryNext<'_, St> { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll { - match Pin::new(&mut *self.stream).try_poll_next(cx) { + match Pin::new(&mut *self.stream).try_poll_next(lw) { 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 582b84230a..4705e1ce8d 100644 --- a/futures-util/src/try_stream/try_skip_while.rs +++ b/futures-util/src/try_stream/try_skip_while.rs @@ -80,12 +80,12 @@ impl Stream for TrySkipWhile lw: &LocalWaker, ) -> Poll> { if *self.done_skipping() { - return self.stream().try_poll_next(cx); + return self.stream().try_poll_next(lw); } loop { if self.pending_item().is_none() { - let item = match ready!(self.stream().try_poll_next(cx)?) { + let item = match ready!(self.stream().try_poll_next(lw)?) { Some(e) => e, None => return Poll::Ready(None), }; @@ -94,7 +94,7 @@ impl Stream for TrySkipWhile *self.pending_item() = Some(item); } - let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().try_poll(cx)?); + let skipped = ready!(self.pending_fut().as_pin_mut().unwrap().try_poll(lw)?); let item = self.pending_item().take().unwrap(); Pin::set(self.pending_fut(), None); diff --git a/futures/tests/abortable.rs b/futures/tests/abortable.rs index 4b1bf3b70a..560cba21f9 100644 --- a/futures/tests/abortable.rs +++ b/futures/tests/abortable.rs @@ -21,14 +21,14 @@ fn abortable_awakens() { let (mut abortable_rx, abort_handle) = abortable(a_rx); let wake_counter = WakeCounter::new(); - let mut cx = panic_context(); - let cx = &mut cx.with_waker(wake_counter.local_waker()); + let mut lw = panic_context(); + let lw = &mut lw.with_waker(wake_counter.local_waker()); assert_eq!(0, wake_counter.count()); - assert_eq!(Poll::Pending, abortable_rx.poll_unpin(cx)); + assert_eq!(Poll::Pending, abortable_rx.poll_unpin(lw)); assert_eq!(0, wake_counter.count()); abort_handle.abort(); assert_eq!(1, wake_counter.count()); - assert_eq!(Poll::Ready(Err(Aborted)), abortable_rx.poll_unpin(cx)); + assert_eq!(Poll::Ready(Err(Aborted)), abortable_rx.poll_unpin(lw)); } #[test] diff --git a/futures/tests/eager_drop.rs b/futures/tests/eager_drop.rs index 6007530771..c7dd50b2af 100644 --- a/futures/tests/eager_drop.rs +++ b/futures/tests/eager_drop.rs @@ -57,7 +57,7 @@ impl Future for FutureData { type Output = F::Output; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - self.future().poll(cx) + self.future().poll(lw) } } diff --git a/futures/tests/fuse.rs b/futures/tests/fuse.rs index 1c7d8e5e80..15b3eccea7 100644 --- a/futures/tests/fuse.rs +++ b/futures/tests/fuse.rs @@ -6,7 +6,7 @@ use futures_test::task::panic_context; #[test] fn fuse() { let mut future = future::ready::(2).fuse(); - let cx = &mut panic_context(); - assert!(future.poll_unpin(cx).is_ready()); - assert!(future.poll_unpin(cx).is_pending()); + let lw = &mut panic_context(); + assert!(future.poll_unpin(lw).is_ready()); + assert!(future.poll_unpin(lw).is_pending()); } diff --git a/futures/tests/futures_ordered.rs b/futures/tests/futures_ordered.rs index 8389febbbc..a872a8a5ed 100644 --- a/futures/tests/futures_ordered.rs +++ b/futures/tests/futures_ordered.rs @@ -38,13 +38,13 @@ fn works_2() { FutureObj::new(Box::new(b_rx.join(c_rx).map(|(a, b)| Ok(a? + b?)))), ]); - let cx = &mut no_spawn_context(); + let lw = &mut no_spawn_context(); a_tx.send(33).unwrap(); b_tx.send(33).unwrap(); - assert!(stream.poll_next_unpin(cx).is_ready()); - assert!(stream.poll_next_unpin(cx).is_pending()); + assert!(stream.poll_next_unpin(lw).is_ready()); + assert!(stream.poll_next_unpin(lw).is_pending()); c_tx.send(33).unwrap(); - assert!(stream.poll_next_unpin(cx).is_ready()); + assert!(stream.poll_next_unpin(lw).is_ready()); } #[test] @@ -70,15 +70,15 @@ fn queue_never_unblocked() { Box::new(b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box))) as _, ]); - with_no_spawn_context(|cx| { + with_no_spawn_context(|lw| { for _ in 0..10 { - assert!(stream.poll_next(cx).unwrap().is_pending()); + assert!(stream.poll_next(lw).unwrap().is_pending()); } b_tx.send(Box::new(())).unwrap(); - assert!(stream.poll_next(cx).unwrap().is_pending()); + assert!(stream.poll_next(lw).unwrap().is_pending()); c_tx.send(Box::new(())).unwrap(); - assert!(stream.poll_next(cx).unwrap().is_pending()); - assert!(stream.poll_next(cx).unwrap().is_pending()); + assert!(stream.poll_next(lw).unwrap().is_pending()); + assert!(stream.poll_next(lw).unwrap().is_pending()); }) }*/ diff --git a/futures/tests/futures_unordered.rs b/futures/tests/futures_unordered.rs index a61adfa533..34765069c0 100644 --- a/futures/tests/futures_unordered.rs +++ b/futures/tests/futures_unordered.rs @@ -42,11 +42,11 @@ fn works_2() { a_tx.send(9).unwrap(); b_tx.send(10).unwrap(); - let cx = &mut no_spawn_context(); - assert_eq!(stream.poll_next_unpin(cx), Poll::Ready(Some(Ok(9)))); + let lw = &mut no_spawn_context(); + assert_eq!(stream.poll_next_unpin(lw), Poll::Ready(Some(Ok(9)))); c_tx.send(20).unwrap(); - assert_eq!(stream.poll_next_unpin(cx), Poll::Ready(Some(Ok(30)))); - assert_eq!(stream.poll_next_unpin(cx), Poll::Ready(None)); + assert_eq!(stream.poll_next_unpin(lw), Poll::Ready(Some(Ok(30)))); + assert_eq!(stream.poll_next_unpin(lw), Poll::Ready(None)); } #[test] @@ -72,16 +72,16 @@ fn finished_future() { //FutureObj::new(Box::new(b_rx.select(c_rx))), ]); - support::with_noop_waker_context(f)(|cx| { + support::with_noop_waker_context(f)(|lw| { for _ in 0..10 { - assert!(stream.poll_next_unpin(cx).is_pending()); + assert!(stream.poll_next_unpin(lw).is_pending()); } b_tx.send(12).unwrap(); - assert!(stream.poll_next_unpin(cx).is_ready()); + assert!(stream.poll_next_unpin(lw).is_ready()); c_tx.send(3).unwrap(); - assert!(stream.poll_next_unpin(cx).is_pending()); - assert!(stream.poll_next_unpin(cx).is_pending()); + assert!(stream.poll_next_unpin(lw).is_pending()); + assert!(stream.poll_next_unpin(lw).is_pending()); }) }*/ diff --git a/futures/tests/split.rs b/futures/tests/split.rs index 73f49b165f..ad9365c311 100644 --- a/futures/tests/split.rs +++ b/futures/tests/split.rs @@ -24,7 +24,7 @@ impl Stream for Join { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.stream().poll_next(cx) + self.stream().poll_next(lw) } } @@ -36,7 +36,7 @@ impl Sink for Join { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_ready(cx) + self.sink().poll_ready(lw) } fn start_send( @@ -50,14 +50,14 @@ impl Sink for Join { mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_flush(cx) + self.sink().poll_flush(lw) } fn poll_close( mut self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - self.sink().poll_close(cx) + self.sink().poll_close(lw) } } diff --git a/futures/tests_disabled/all.rs b/futures/tests_disabled/all.rs index 661b9609b7..691073768a 100644 --- a/futures/tests_disabled/all.rs +++ b/futures/tests_disabled/all.rs @@ -124,7 +124,7 @@ fn smoke_oneshot() { let (c, mut p) = oneshot::channel::(); drop(c); - let res = panic_waker_cx(|cx| p.poll(cx)); + let res = panic_waker_lw(|lw| p.poll(lw)); assert!(res.is_err()); let (c, p) = oneshot::channel::(); drop(c); @@ -147,8 +147,8 @@ fn select_cancels() { assert!(brx.try_recv().is_err()); assert!(drx.try_recv().is_err()); a.send(1).unwrap(); - noop_waker_cx(|cx| { - let res = f.poll(cx); + noop_waker_lw(|lw| { + let res = f.poll(lw); assert!(res.ok().unwrap().is_ready()); assert_eq!(brx.recv().unwrap(), 1); drop(c); @@ -160,10 +160,10 @@ fn select_cancels() { let d = d.map(move |d| { dtx.send(d).unwrap(); d }); let mut f = b.select(d).then(unselect); - assert!(f.poll(cx).ok().unwrap().is_pending()); - assert!(f.poll(cx).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); a.send(1).unwrap(); - assert!(f.poll(cx).ok().unwrap().is_ready()); + assert!(f.poll(lw).ok().unwrap().is_ready()); drop((c, f)); assert!(drx.recv().is_err()); }) @@ -178,7 +178,7 @@ fn join_cancels() { let mut f = b.join(d); drop(a); - let res = panic_waker_cx(|cx| f.poll(cx)); + let res = panic_waker_lw(|lw| f.poll(lw)); assert!(res.is_err()); drop(c); assert!(drx.recv().is_err()); @@ -206,39 +206,39 @@ fn join_cancels() { fn join_incomplete() { let (a, b) = oneshot::channel::(); let (tx, rx) = channel(); - noop_waker_cx(|cx| { + noop_waker_lw(|lw| { let mut f = ok(1).join(b).map(move |r| tx.send(r).unwrap()); - assert!(f.poll(cx).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); assert!(rx.try_recv().is_err()); a.send(2).unwrap(); - assert!(f.poll(cx).ok().unwrap().is_ready()); + assert!(f.poll(lw).ok().unwrap().is_ready()); assert_eq!(rx.recv().unwrap(), (1, 2)); let (a, b) = oneshot::channel::(); let (tx, rx) = channel(); let mut f = b.join(Ok(2)).map(move |r| tx.send(r).unwrap()); - assert!(f.poll(cx).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); assert!(rx.try_recv().is_err()); a.send(1).unwrap(); - assert!(f.poll(cx).ok().unwrap().is_ready()); + assert!(f.poll(lw).ok().unwrap().is_ready()); assert_eq!(rx.recv().unwrap(), (1, 2)); let (a, b) = oneshot::channel::(); let (tx, rx) = channel(); let mut f = ok(1).join(b).map_err(move |_r| tx.send(2).unwrap()); - assert!(f.poll(cx).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); assert!(rx.try_recv().is_err()); drop(a); - assert!(f.poll(cx).is_err()); + assert!(f.poll(lw).is_err()); assert_eq!(rx.recv().unwrap(), 2); let (a, b) = oneshot::channel::(); let (tx, rx) = channel(); let mut f = b.join(Ok(2)).map_err(move |_r| tx.send(1).unwrap()); - assert!(f.poll(cx).ok().unwrap().is_pending()); + assert!(f.poll(lw).ok().unwrap().is_pending()); assert!(rx.try_recv().is_err()); drop(a); - assert!(f.poll(cx).is_err()); + assert!(f.poll(lw).is_err()); assert_eq!(rx.recv().unwrap(), 1); }) } @@ -340,7 +340,7 @@ fn select2() { let b = b.map(move |v| { btx.send(v).unwrap(); v }); let d = d.map(move |v| { dtx.send(v).unwrap(); v }); let mut f = b.select(d); - let _res = noop_waker_cx(|cx| f.poll(cx)); + let _res = noop_waker_lw(|lw| f.poll(lw)); drop(f); assert!(drx.recv().is_err()); assert!(brx.recv().is_err()); diff --git a/futures/tests_disabled/ready_queue.rs b/futures/tests_disabled/ready_queue.rs index 6face1eb14..db0b69a5e4 100644 --- a/futures/tests_disabled/ready_queue.rs +++ b/futures/tests_disabled/ready_queue.rs @@ -12,7 +12,7 @@ impl AssertSendSync for FuturesUnordered<()> {} #[test] fn basic_usage() { - block_on(future::lazy(move |cx| { + block_on(future::lazy(move |lw| { let mut queue = FuturesUnordered::new(); let (tx1, rx1) = oneshot::channel(); let (tx2, rx2) = oneshot::channel(); @@ -22,19 +22,19 @@ fn basic_usage() { queue.push(rx2); queue.push(rx3); - assert!(!queue.poll_next(cx).unwrap().is_ready()); + assert!(!queue.poll_next(lw).unwrap().is_ready()); tx2.send("hello").unwrap(); - assert_eq!(Ready(Some("hello")), queue.poll_next(cx).unwrap()); - assert!(!queue.poll_next(cx).unwrap().is_ready()); + assert_eq!(Ready(Some("hello")), queue.poll_next(lw).unwrap()); + assert!(!queue.poll_next(lw).unwrap().is_ready()); tx1.send("world").unwrap(); tx3.send("world2").unwrap(); - assert_eq!(Ready(Some("world")), queue.poll_next(cx).unwrap()); - assert_eq!(Ready(Some("world2")), queue.poll_next(cx).unwrap()); - assert_eq!(Ready(None), queue.poll_next(cx).unwrap()); + assert_eq!(Ready(Some("world")), queue.poll_next(lw).unwrap()); + assert_eq!(Ready(Some("world2")), queue.poll_next(lw).unwrap()); + assert_eq!(Ready(None), queue.poll_next(lw).unwrap()); Ok::<_, ()>(()) })).unwrap(); @@ -42,7 +42,7 @@ fn basic_usage() { #[test] fn resolving_errors() { - block_on(future::lazy(move |cx| { + block_on(future::lazy(move |lw| { let mut queue = FuturesUnordered::new(); let (tx1, rx1) = oneshot::channel(); let (tx2, rx2) = oneshot::channel(); @@ -52,19 +52,19 @@ fn resolving_errors() { queue.push(rx2); queue.push(rx3); - assert!(!queue.poll_next(cx).unwrap().is_ready()); + assert!(!queue.poll_next(lw).unwrap().is_ready()); drop(tx2); - assert!(queue.poll_next(cx).is_err()); - assert!(!queue.poll_next(cx).unwrap().is_ready()); + assert!(queue.poll_next(lw).is_err()); + assert!(!queue.poll_next(lw).unwrap().is_ready()); drop(tx1); tx3.send("world2").unwrap(); - assert!(queue.poll_next(cx).is_err()); - assert_eq!(Ready(Some("world2")), queue.poll_next(cx).unwrap()); - assert_eq!(Ready(None), queue.poll_next(cx).unwrap()); + assert!(queue.poll_next(lw).is_err()); + assert_eq!(Ready(Some("world2")), queue.poll_next(lw).unwrap()); + assert_eq!(Ready(None), queue.poll_next(lw).unwrap()); Ok::<_, ()>(()) })).unwrap(); @@ -82,16 +82,16 @@ fn dropping_ready_queue() { queue.push(rx2); queue.push(rx3); - support::noop_waker_cx(|cx| { - assert!(!tx1.poll_cancel(cx).unwrap().is_ready()); - assert!(!tx2.poll_cancel(cx).unwrap().is_ready()); - assert!(!tx3.poll_cancel(cx).unwrap().is_ready()); + support::noop_waker_lw(|lw| { + assert!(!tx1.poll_cancel(lw).unwrap().is_ready()); + assert!(!tx2.poll_cancel(lw).unwrap().is_ready()); + assert!(!tx3.poll_cancel(lw).unwrap().is_ready()); drop(queue); - assert!(tx1.poll_cancel(cx).unwrap().is_ready()); - assert!(tx2.poll_cancel(cx).unwrap().is_ready()); - assert!(tx3.poll_cancel(cx).unwrap().is_ready()); + assert!(tx1.poll_cancel(lw).unwrap().is_ready()); + assert!(tx2.poll_cancel(lw).unwrap().is_ready()); + assert!(tx3.poll_cancel(lw).unwrap().is_ready()); }); Ok::<_, ()>(()).into_future() @@ -149,16 +149,16 @@ fn stress() { #[test] fn panicking_future_dropped() { - block_on(future::lazy(move |cx| { + block_on(future::lazy(move |lw| { let mut queue = FuturesUnordered::new(); queue.push(future::poll_fn(|_| -> Poll { panic!() })); - let r = panic::catch_unwind(AssertUnwindSafe(|| queue.poll_next(cx))); + let r = panic::catch_unwind(AssertUnwindSafe(|| queue.poll_next(lw))); assert!(r.is_err()); assert!(queue.is_empty()); - assert_eq!(Ready(None), queue.poll_next(cx).unwrap()); + assert_eq!(Ready(None), queue.poll_next(lw).unwrap()); Ok::<_, ()>(()) })).unwrap(); diff --git a/futures/tests_disabled/sink.rs b/futures/tests_disabled/sink.rs index d227af426a..9c44ddad06 100644 --- a/futures/tests_disabled/sink.rs +++ b/futures/tests_disabled/sink.rs @@ -97,7 +97,7 @@ impl Wake for Flag { } } -fn flag_cx(f: F) -> R +fn flag_lw(f: F) -> R where F: FnOnce(Arc, &LocalWaker) -> R { let flag = Flag::new(); @@ -105,8 +105,8 @@ fn flag_cx(f: F) -> R let waker = Waker::from(flag.clone()); let exec = &mut support::PanicExec; - let cx = &LocalWaker::new(map, &waker, exec); - f(flag, cx) + let lw = &LocalWaker::new(map, &waker, exec); + f(flag, lw) } // Sends a value on an i32 channel sink @@ -125,7 +125,7 @@ impl Future for StartSendFut { fn poll(&mut self, lw: &LocalWaker) -> Poll { { let inner = self.0.as_mut().unwrap(); - try_ready!(inner.poll_ready(cx)); + try_ready!(inner.poll_ready(lw)); inner.start_send(self.1.take().unwrap())?; } Ok(Async::Ready(self.0.take().unwrap())) @@ -141,15 +141,15 @@ fn mpsc_blocking_start_send() { block_on(futures::future::lazy(|_| { tx.start_send(0).unwrap(); - flag_cx(|flag, cx| { + flag_lw(|flag, lw| { let mut task = StartSendFut::new(tx, 1); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); assert!(!flag.get()); sassert_next(&mut rx, 0); assert!(flag.get()); flag.set(false); - assert!(task.poll(cx).unwrap().is_ready()); + assert!(task.poll(lw).unwrap().is_ready()); assert!(!flag.get()); sassert_next(&mut rx, 1); @@ -171,13 +171,13 @@ fn with_flush() { assert_eq!(sink.start_send(0), Ok(())); - flag_cx(|flag, cx| { + flag_lw(|flag, lw| { let mut task = sink.flush(); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); tx.send(()).unwrap(); assert!(flag.get()); - let sink = match task.poll(cx).unwrap() { + let sink = match task.poll(lw).unwrap() { Async::Ready(sink) => sink, _ => panic!() }; @@ -239,13 +239,13 @@ impl Sink for ManualFlush { if self.data.is_empty() { Ok(Async::Ready(())) } else { - self.waiting_tasks.push(cx.waker().clone()); + self.waiting_tasks.push(lw.waker().clone()); Ok(Async::Pending) } } fn poll_close(&mut self, lw: &LocalWaker) -> Poll<(), Self::SinkError> { - self.poll_flush(cx) + self.poll_flush(lw) } } @@ -270,18 +270,18 @@ impl ManualFlush { // but doesn't claim to be flushed until the underlying sink is fn with_flush_propagate() { let mut sink = ManualFlush::new().with(|x| -> Result, ()> { Ok(x) }); - flag_cx(|flag, cx| { - assert!(sink.poll_ready(cx).unwrap().is_ready()); + flag_lw(|flag, lw| { + assert!(sink.poll_ready(lw).unwrap().is_ready()); sink.start_send(Some(0)).unwrap(); - assert!(sink.poll_ready(cx).unwrap().is_ready()); + assert!(sink.poll_ready(lw).unwrap().is_ready()); sink.start_send(Some(1)).unwrap(); let mut task = sink.flush(); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); assert!(!flag.get()); assert_eq!(task.get_mut().unwrap().get_mut().force_flush(), vec![0, 1]); assert!(flag.get()); - assert!(task.poll(cx).unwrap().is_ready()); + assert!(task.poll(lw).unwrap().is_ready()); }) } @@ -321,7 +321,7 @@ impl Allow { if self.flag.get() { true } else { - self.tasks.borrow_mut().push(cx.waker().clone()); + self.tasks.borrow_mut().push(lw.waker().clone()); false } } @@ -340,7 +340,7 @@ impl Sink for ManualAllow { type SinkError = Never; fn poll_ready(&mut self, lw: &LocalWaker) -> Poll<(), Self::SinkError> { - if self.allow.check(cx) { + if self.allow.check(lw) { Ok(Async::Ready(())) } else { Ok(Async::Pending) @@ -380,13 +380,13 @@ fn buffer() { let sink = block_on(StartSendFut::new(sink, 0)).unwrap(); let sink = block_on(StartSendFut::new(sink, 1)).unwrap(); - flag_cx(|flag, cx| { + flag_lw(|flag, lw| { let mut task = sink.send(2); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); assert!(!flag.get()); allow.start(); assert!(flag.get()); - match task.poll(cx).unwrap() { + match task.poll(lw).unwrap() { Async::Ready(sink) => { assert_eq!(sink.get_ref().data, vec![0, 1, 2]); } @@ -415,18 +415,18 @@ fn fanout_backpressure() { let sink = block_on(StartSendFut::new(sink, 0)).unwrap(); - flag_cx(|flag, cx| { + flag_lw(|flag, lw| { let mut task = sink.send(2); assert!(!flag.get()); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); let (item, left_recv) = block_on(left_recv.next()).unwrap(); assert_eq!(item, Some(0)); assert!(flag.get()); - assert!(task.poll(cx).unwrap().is_pending()); + assert!(task.poll(lw).unwrap().is_pending()); let (item, right_recv) = block_on(right_recv.next()).unwrap(); assert_eq!(item, Some(0)); assert!(flag.get()); - assert!(task.poll(cx).unwrap().is_ready()); + assert!(task.poll(lw).unwrap().is_ready()); // make sure receivers live until end of test to prevent send errors drop(left_recv); drop(right_recv); @@ -435,11 +435,11 @@ fn fanout_backpressure() { #[test] fn map_err() { - panic_waker_cx(|cx| { + panic_waker_lw(|lw| { let (tx, _rx) = mpsc::channel(1); let mut tx = tx.sink_map_err(|_| ()); assert_eq!(tx.start_send(()), Ok(())); - assert_eq!(tx.poll_flush(cx), Ok(Async::Ready(()))); + assert_eq!(tx.poll_flush(lw), Ok(Async::Ready(()))); }); let tx = mpsc::channel(0).0; @@ -457,11 +457,11 @@ impl From for FromErrTest { #[test] fn from_err() { - panic_waker_cx(|cx| { + panic_waker_lw(|lw| { let (tx, _rx) = mpsc::channel(1); let mut tx: SinkErrInto, FromErrTest> = tx.sink_err_into(); assert_eq!(tx.start_send(()), Ok(())); - assert_eq!(tx.poll_flush(cx), Ok(Async::Ready(()))); + assert_eq!(tx.poll_flush(lw), Ok(Async::Ready(()))); }); let tx = mpsc::channel(0).0; diff --git a/futures/tests_disabled/stream.rs b/futures/tests_disabled/stream.rs index 2ee7076660..f4c89ea82e 100644 --- a/futures/tests_disabled/stream.rs +++ b/futures/tests_disabled/stream.rs @@ -290,11 +290,11 @@ fn peek() { fn poll(&mut self, lw: &LocalWaker) -> Poll<(), u32> { { - let res = try_ready!(self.inner.peek(cx)); + let res = try_ready!(self.inner.peek(lw)); assert_eq!(res, Some(&1)); } - assert_eq!(self.inner.peek(cx).unwrap(), Some(&1).into()); - assert_eq!(self.inner.poll_next(cx).unwrap(), Some(1).into()); + assert_eq!(self.inner.peek(lw).unwrap(), Some(&1).into()); + assert_eq!(self.inner.poll_next(lw).unwrap(), Some(1).into()); Ok(Async::Ready(())) } } From 7a3d1947b8737821aad574e0cdc4762e514b7041 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 24 Sep 2018 18:24:55 -0700 Subject: [PATCH 06/14] Update futures-{channel, io, sink, util} --- futures-channel/src/mpsc/mod.rs | 8 +- futures-channel/src/oneshot.rs | 6 +- futures-io/src/lib.rs | 2 +- futures-sink/src/channel_impls.rs | 2 +- futures-sink/src/lib.rs | 2 +- futures-util/Cargo.toml | 3 +- futures-util/benches_disabled/bilock.rs | 2 +- futures-util/src/async_await/pending.rs | 2 +- futures-util/src/async_await/poll.rs | 2 +- futures-util/src/future/abortable.rs | 4 +- futures-util/src/future/catch_unwind.rs | 2 +- futures-util/src/future/chain.rs | 2 +- futures-util/src/future/empty.rs | 2 +- futures-util/src/future/flatten.rs | 2 +- futures-util/src/future/flatten_stream.rs | 2 +- futures-util/src/future/fuse.rs | 2 +- futures-util/src/future/inspect.rs | 2 +- futures-util/src/future/into_stream.rs | 2 +- futures-util/src/future/join.rs | 2 +- futures-util/src/future/lazy.rs | 2 +- futures-util/src/future/map.rs | 2 +- futures-util/src/future/maybe_done.rs | 2 +- futures-util/src/future/mod.rs | 59 ++++-------- futures-util/src/future/option.rs | 2 +- futures-util/src/future/poll_fn.rs | 4 +- futures-util/src/future/ready.rs | 2 +- .../remote_handle.rs} | 91 +++++++++++-------- futures-util/src/future/shared.rs | 12 +-- futures-util/src/future/then.rs | 2 +- futures-util/src/future/unit_error.rs | 2 +- futures-util/src/future/with_spawner.rs | 2 +- futures-util/src/io/allow_std.rs | 2 +- futures-util/src/io/close.rs | 2 +- futures-util/src/io/copy_into.rs | 2 +- futures-util/src/io/flush.rs | 2 +- futures-util/src/io/read.rs | 2 +- futures-util/src/io/read_exact.rs | 2 +- futures-util/src/io/read_to_end.rs | 2 +- futures-util/src/io/split.rs | 2 +- futures-util/src/io/write_all.rs | 2 +- futures-util/src/lib.rs | 6 +- futures-util/src/lock.rs | 4 +- futures-util/src/sink/buffer.rs | 2 +- futures-util/src/sink/close.rs | 2 +- futures-util/src/sink/drain.rs | 2 +- futures-util/src/sink/err_into.rs | 2 +- futures-util/src/sink/fanout.rs | 2 +- futures-util/src/sink/flush.rs | 2 +- futures-util/src/sink/map_err.rs | 2 +- futures-util/src/sink/send.rs | 2 +- futures-util/src/sink/send_all.rs | 2 +- futures-util/src/sink/with.rs | 2 +- futures-util/src/sink/with_flat_map.rs | 2 +- futures-util/src/stream/buffer_unordered.rs | 2 +- futures-util/src/stream/buffered.rs | 2 +- futures-util/src/stream/catch_unwind.rs | 2 +- futures-util/src/stream/chain.rs | 2 +- futures-util/src/stream/chunks.rs | 2 +- futures-util/src/stream/collect.rs | 2 +- futures-util/src/stream/concat.rs | 2 +- futures-util/src/stream/empty.rs | 2 +- futures-util/src/stream/filter.rs | 2 +- futures-util/src/stream/filter_map.rs | 2 +- futures-util/src/stream/flatten.rs | 2 +- futures-util/src/stream/fold.rs | 2 +- futures-util/src/stream/for_each.rs | 2 +- .../src/stream/for_each_concurrent.rs | 2 +- futures-util/src/stream/forward.rs | 2 +- futures-util/src/stream/fuse.rs | 2 +- futures-util/src/stream/futures_ordered.rs | 2 +- .../src/stream/futures_unordered/mod.rs | 13 ++- futures-util/src/stream/inspect.rs | 2 +- futures-util/src/stream/into_future.rs | 2 +- futures-util/src/stream/iter.rs | 2 +- futures-util/src/stream/map.rs | 2 +- futures-util/src/stream/mod.rs | 2 +- futures-util/src/stream/next.rs | 2 +- futures-util/src/stream/once.rs | 2 +- futures-util/src/stream/peek.rs | 2 +- futures-util/src/stream/poll_fn.rs | 2 +- futures-util/src/stream/repeat.rs | 2 +- futures-util/src/stream/select.rs | 2 +- futures-util/src/stream/skip.rs | 2 +- futures-util/src/stream/skip_while.rs | 2 +- futures-util/src/stream/split.rs | 2 +- futures-util/src/stream/take.rs | 2 +- futures-util/src/stream/take_while.rs | 2 +- futures-util/src/stream/then.rs | 2 +- futures-util/src/stream/unfold.rs | 2 +- futures-util/src/stream/zip.rs | 2 +- futures-util/src/task/atomic_waker.rs | 10 +- futures-util/src/task/mod.rs | 5 - futures-util/src/task/spawn/mod.rs | 85 ----------------- futures-util/src/task/spawn/spawn_error.rs | 8 -- futures-util/src/try_future/and_then.rs | 2 +- futures-util/src/try_future/err_into.rs | 2 +- futures-util/src/try_future/flatten_sink.rs | 2 +- futures-util/src/try_future/into_future.rs | 2 +- futures-util/src/try_future/map_err.rs | 2 +- futures-util/src/try_future/map_ok.rs | 2 +- futures-util/src/try_future/or_else.rs | 2 +- futures-util/src/try_future/try_chain.rs | 2 +- futures-util/src/try_future/try_join.rs | 2 +- futures-util/src/try_future/unwrap_or_else.rs | 2 +- futures-util/src/try_stream/err_into.rs | 2 +- futures-util/src/try_stream/into_stream.rs | 2 +- futures-util/src/try_stream/map_err.rs | 2 +- futures-util/src/try_stream/map_ok.rs | 2 +- .../src/try_stream/try_buffer_unordered.rs | 2 +- futures-util/src/try_stream/try_collect.rs | 2 +- futures-util/src/try_stream/try_filter_map.rs | 2 +- futures-util/src/try_stream/try_fold.rs | 2 +- futures-util/src/try_stream/try_for_each.rs | 2 +- .../src/try_stream/try_for_each_concurrent.rs | 2 +- futures-util/src/try_stream/try_next.rs | 2 +- futures-util/src/try_stream/try_skip_while.rs | 2 +- 116 files changed, 202 insertions(+), 318 deletions(-) rename futures-util/src/{task/spawn/spawn_with_handle.rs => future/remote_handle.rs} (53%) delete mode 100644 futures-util/src/task/spawn/mod.rs delete mode 100644 futures-util/src/task/spawn/spawn_error.rs diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index ca7facd444..ac730b3578 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -79,7 +79,7 @@ // by the queue structure. use futures_core::stream::Stream; -use futures_core::task::{self, Waker, Poll}; +use futures_core::task::{LocalWaker, Waker, Poll}; use std::any::Any; use std::error::Error; use std::fmt; @@ -619,7 +619,7 @@ impl Sender { fn park(&mut self, lw: Option<&LocalWaker>) { // TODO: clean up internal state if the task::current will fail - let task = lw.map(|lw| lw.waker().clone()); + let task = lw.map(|lw| lw.clone().into_waker()); { let mut sender = self.sender_task.lock().unwrap(); @@ -695,7 +695,7 @@ impl Sender { // // Update the task in case the `Sender` has been moved to another // task - task.task = lw.map(|lw| lw.waker().clone()); + task.task = lw.map(|lw| lw.clone().into_waker()); Poll::Pending } else { @@ -932,7 +932,7 @@ impl Receiver { return TryPark::NotEmpty; } - recv_task.task = Some(lw.waker().clone()); + recv_task.task = Some(lw.clone().into_waker()); TryPark::Parked } diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index 86e4063ce6..2b3cadb909 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -1,7 +1,7 @@ //! A channel for sending a single message between asynchronous tasks. use futures_core::future::Future; -use futures_core::task::{self, Poll, Waker}; +use futures_core::task::{LocalWaker, Poll, Waker}; use std::marker::Unpin; use std::pin::Pin; use std::sync::Arc; @@ -177,7 +177,7 @@ impl Inner { // `Receiver` may have been dropped. The first thing it does is set the // flag, and if it fails to acquire the lock it assumes that we'll see // the flag later on. So... we then try to see the flag later on! - let handle = lw.waker().clone(); + let handle = lw.clone().into_waker(); match self.tx_task.try_lock() { Some(mut p) => *p = Some(handle), None => return Poll::Ready(()), @@ -261,7 +261,7 @@ impl Inner { let done = if self.complete.load(SeqCst) { true } else { - let task = lw.waker().clone(); + let task = lw.clone().into_waker(); match self.rx_task.try_lock() { Some(mut slot) => { *slot = Some(task); false }, None => true, diff --git a/futures-io/src/lib.rs b/futures-io/src/lib.rs index c113f14d59..1cc4c4e10d 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -21,7 +21,7 @@ macro_rules! if_std { } if_std! { - use futures_core::task::{self, Poll}; + use futures_core::task::{LocalWaker, Poll}; use std::boxed::Box; use std::cmp; use std::io as StdIo; diff --git a/futures-sink/src/channel_impls.rs b/futures-sink/src/channel_impls.rs index ecf2d98d4a..edd3f6fc82 100644 --- a/futures-sink/src/channel_impls.rs +++ b/futures-sink/src/channel_impls.rs @@ -1,5 +1,5 @@ use crate::{Sink, Poll}; -use futures_core::task; +use futures_core::task::LocalWaker; use futures_channel::mpsc::{Sender, SendError, UnboundedSender}; use std::pin::Pin; diff --git a/futures-sink/src/lib.rs b/futures-sink/src/lib.rs index 65968bb61a..0c69e9ff05 100644 --- a/futures-sink/src/lib.rs +++ b/futures-sink/src/lib.rs @@ -16,7 +16,7 @@ macro_rules! if_std { )*) } -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use core::marker::Unpin; use core::pin::Pin; diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index cb38f6d7fe..5a065e44d1 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -18,7 +18,7 @@ name = "futures_util" std = ["futures-core-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "either/use_std", "slab"] default = ["std", "futures-core-preview/either", "futures-sink-preview/either"] compat = ["std", "futures"] -tokio-compat = ["compat", "tokio-executor"] +tokio-compat = ["compat"] bench = [] nightly = [] @@ -30,7 +30,6 @@ futures-sink-preview = { path = "../futures-sink", version = "0.3.0-alpha.6", de either = { version = "1.4", default-features = false } slab = { version = "0.4", optional = true } futures = { version = "0.1", optional = true } -tokio-executor = { version = "0.1.2", optional = true } pin-utils = "0.1.0-alpha.2" [dev-dependencies] diff --git a/futures-util/benches_disabled/bilock.rs b/futures-util/benches_disabled/bilock.rs index e8dbdf1428..b8fd377c12 100644 --- a/futures-util/benches_disabled/bilock.rs +++ b/futures-util/benches_disabled/bilock.rs @@ -2,7 +2,7 @@ #[cfg(feature = "bench")] mod bench { -use futures::task::{self, Wake, Waker}; +use futures::task::{LocalWaker, Wake, Waker}; use futures::executor::LocalPool; use futures_util::lock::BiLock; use futures_util::lock::BiLockAcquire; diff --git a/futures-util/src/async_await/pending.rs b/futures-util/src/async_await/pending.rs index dc48e3a6eb..e84489ae9f 100644 --- a/futures-util/src/async_await/pending.rs +++ b/futures-util/src/async_await/pending.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A macro which yields to the event loop once. /// diff --git a/futures-util/src/async_await/poll.rs b/futures-util/src/async_await/poll.rs index 08762b754a..2e8efd7728 100644 --- a/futures-util/src/async_await/poll.rs +++ b/futures-util/src/async_await/poll.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A macro which returns the result of polling a future once within the /// current `async` context. diff --git a/futures-util/src/future/abortable.rs b/futures-util/src/future/abortable.rs index b4475103d9..f5f124725b 100644 --- a/futures-util/src/future/abortable.rs +++ b/futures-util/src/future/abortable.rs @@ -1,6 +1,6 @@ use crate::task::AtomicWaker; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; use std::marker::Unpin; use std::pin::Pin; @@ -134,7 +134,7 @@ impl Future for Abortable where Fut: Future { } // Register to receive a wakeup if the future is aborted in the... future - self.inner.waker.register(lw.waker()); + self.inner.waker.register(lw); // Check to see if the future was aborted between the first check and // registration. diff --git a/futures-util/src/future/catch_unwind.rs b/futures-util/src/future/catch_unwind.rs index 4aa7d109d2..2eb7c6524d 100644 --- a/futures-util/src/future/catch_unwind.rs +++ b/futures-util/src/future/catch_unwind.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; use std::any::Any; use std::pin::Pin; diff --git a/futures-util/src/future/chain.rs b/futures-util/src/future/chain.rs index 3bb50aac90..4eb6308d65 100644 --- a/futures-util/src/future/chain.rs +++ b/futures-util/src/future/chain.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; #[must_use = "futures do nothing unless polled"] #[derive(Debug)] diff --git a/futures-util/src/future/empty.rs b/futures-util/src/future/empty.rs index f0237968c6..9e3f20ae76 100644 --- a/futures-util/src/future/empty.rs +++ b/futures-util/src/future/empty.rs @@ -1,7 +1,7 @@ use core::marker; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future which is never resolved. /// diff --git a/futures-util/src/future/flatten.rs b/futures-util/src/future/flatten.rs index e09124c351..471e2f26ca 100644 --- a/futures-util/src/future/flatten.rs +++ b/futures-util/src/future/flatten.rs @@ -2,7 +2,7 @@ use super::chain::Chain; use core::fmt; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the `flatten` combinator. diff --git a/futures-util/src/future/flatten_stream.rs b/futures-util/src/future/flatten_stream.rs index b969f55481..814597147b 100644 --- a/futures-util/src/future/flatten_stream.rs +++ b/futures-util/src/future/flatten_stream.rs @@ -2,7 +2,7 @@ use core::fmt; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// Future for the `flatten_stream` combinator, flattening a /// future-of-a-stream to get just the result of the final stream as a stream. diff --git a/futures-util/src/future/fuse.rs b/futures-util/src/future/fuse.rs index b42a31ecce..d9a35d6cd5 100644 --- a/futures-util/src/future/fuse.rs +++ b/futures-util/src/future/fuse.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// A future which "fuses" a future once it's been resolved. diff --git a/futures-util/src/future/inspect.rs b/futures-util/src/future/inspect.rs index 5ddcf6520c..62a51b6546 100644 --- a/futures-util/src/future/inspect.rs +++ b/futures-util/src/future/inspect.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Do something with the item of a future, passing it on. diff --git a/futures-util/src/future/into_stream.rs b/futures-util/src/future/into_stream.rs index 06c6824b56..001b9ebea9 100644 --- a/futures-util/src/future/into_stream.rs +++ b/futures-util/src/future/into_stream.rs @@ -1,7 +1,7 @@ use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// A type which converts a `Future` into a `Stream` diff --git a/futures-util/src/future/join.rs b/futures-util/src/future/join.rs index 1d03a4d49f..633beaf904 100644 --- a/futures-util/src/future/join.rs +++ b/futures-util/src/future/join.rs @@ -4,7 +4,7 @@ use crate::future::{MaybeDone, maybe_done}; use core::fmt; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; macro_rules! generate { diff --git a/futures-util/src/future/lazy.rs b/futures-util/src/future/lazy.rs index a249fcbd6d..492d3b36ea 100644 --- a/futures-util/src/future/lazy.rs +++ b/futures-util/src/future/lazy.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future which, when polled, invokes a closure and yields its result. /// diff --git a/futures-util/src/future/map.rs b/futures-util/src/future/map.rs index e47b0fa052..11ea79d047 100644 --- a/futures-util/src/future/map.rs +++ b/futures-util/src/future/map.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Future for the `map` combinator, changing the type of a future. diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index 8af3aec285..43c4732121 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -4,7 +4,7 @@ use core::marker::Unpin; use core::mem; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future that may have completed. /// diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 033f84f8f1..018e6a37d2 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -7,7 +7,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll, Spawn}; +use futures_core::task::{LocalWaker, Poll}; // Primitive futures mod empty; @@ -60,9 +60,6 @@ pub use self::inspect::Inspect; mod unit_error; pub use self::unit_error::UnitError; -mod with_spawner; -pub use self::with_spawner::WithSpawner; - // Implementation details mod chain; pub(crate) use self::chain::Chain; @@ -74,6 +71,9 @@ if_std! { mod catch_unwind; pub use self::catch_unwind::CatchUnwind; + mod remote_handle; + pub use self::remote_handle::{Remote, RemoteHandle}; + // ToDo // mod join_all; // pub use self::join_all::{join_all, JoinAll}; @@ -621,6 +621,18 @@ pub trait FutureExt: Future { Shared::new(self) } + /// Turn this future into a future that yields `()` on completion and sends + /// its output to another future on a separate task. + /// + /// This can be used with spawning executors to easily retrieve the result + /// of a future executing on a separate task or thread. + fn remote_handle(self) -> (Remote, RemoteHandle) + where + Self: Sized, + { + remote_handle::remote_handle(self) + } + /// Wrap the future in a Box, pinning it. #[cfg(feature = "std")] fn boxed(self) -> Pin> @@ -636,45 +648,6 @@ pub trait FutureExt: Future { UnitError::new(self) } - /// Assigns the provided `Spawn` to be used when spawning tasks - /// from within the future. - /// - /// # Examples - /// - /// ``` - /// #![feature(async_await, await_macro, futures_api)] - /// # futures::executor::block_on(async { - /// use futures::spawn; - /// use futures::executor::ThreadPool; - /// use futures::future::FutureExt; - /// use std::thread; - /// # let (tx, rx) = futures::channel::oneshot::channel(); - /// - /// let pool = ThreadPool::builder() - /// .name_prefix("my-pool-") - /// .pool_size(1) - /// .create().unwrap(); - /// - /// let val = await!((async { - /// assert_ne!(thread::current().name(), Some("my-pool-0")); - /// - /// // Spawned task runs on the executor specified via `with_spawner` - /// spawn!(async { - /// assert_eq!(thread::current().name(), Some("my-pool-0")); - /// # tx.send("ran").unwrap(); - /// }).unwrap(); - /// }).with_spawner(pool)); - /// - /// # assert_eq!(await!(rx), Ok("ran")) - /// # }) - /// ``` - fn with_spawner(self, spawner: Sp) -> WithSpawner - where Self: Sized, - Sp: Spawn - { - WithSpawner::new(self, spawner) - } - /// A convenience for calling `Future::poll` on `Unpin` future types. fn poll_unpin(&mut self, lw: &LocalWaker) -> Poll where Self: Unpin + Sized diff --git a/futures-util/src/future/option.rs b/futures-util/src/future/option.rs index b538a61469..11afa06e23 100644 --- a/futures-util/src/future/option.rs +++ b/futures-util/src/future/option.rs @@ -2,7 +2,7 @@ use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// A future representing a value which may or may not be present. diff --git a/futures-util/src/future/poll_fn.rs b/futures-util/src/future/poll_fn.rs index 50e4690835..2a41baff77 100644 --- a/futures-util/src/future/poll_fn.rs +++ b/futures-util/src/future/poll_fn.rs @@ -3,7 +3,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future which wraps a function returning [`Poll`]. /// @@ -26,7 +26,7 @@ impl Unpin for PollFn {} /// #![feature(async_await, await_macro, futures_api)] /// # futures::executor::block_on(async { /// use futures::future::poll_fn; -/// use futures::task::{self, Poll}; +/// use futures::task::{LocalWaker, Poll}; /// /// fn read_line(lw: &LocalWaker) -> Poll { /// Poll::Ready("Hello, World!".into()) diff --git a/futures-util/src/future/ready.rs b/futures-util/src/future/ready.rs index e69930003d..bc15e589b9 100644 --- a/futures-util/src/future/ready.rs +++ b/futures-util/src/future/ready.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future that is immediately ready with a value /// diff --git a/futures-util/src/task/spawn/spawn_with_handle.rs b/futures-util/src/future/remote_handle.rs similarity index 53% rename from futures-util/src/task/spawn/spawn_with_handle.rs rename to futures-util/src/future/remote_handle.rs index 53d15aaa47..d0e819d4f5 100644 --- a/futures-util/src/task/spawn/spawn_with_handle.rs +++ b/futures-util/src/future/remote_handle.rs @@ -1,26 +1,35 @@ -use crate::future::FutureExt; -use super::SpawnError; -use futures_channel::oneshot::{self, Sender, Receiver}; -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::Pin; -use std::panic::{self, AssertUnwindSafe}; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::thread; - -/// The join handle returned by -/// [`spawn_with_handle`](crate::task::SpawnExt::spawn_with_handle). +use { + crate::future::{CatchUnwind, FutureExt}, + futures_channel::oneshot::{self, Sender, Receiver}, + futures_core::{ + future::Future, + task::{LocalWaker, Poll}, + }, + pin_utils::{unsafe_pinned, unsafe_unpinned}, + std::{ + any::Any, + fmt, + marker::Unpin, + panic::{self, AssertUnwindSafe}, + pin::Pin, + sync::{ + Arc, + atomic::{AtomicBool, Ordering}, + }, + thread, + }, +}; + +/// The handle to a remote future returned by +/// [`remote_handle`](crate::future::FutureExt::remote_handle). #[must_use = "futures do nothing unless polled"] #[derive(Debug)] -pub struct JoinHandle { +pub struct RemoteHandle { rx: Receiver>, keep_running: Arc, } -impl JoinHandle { +impl RemoteHandle { /// Drops this handle *without* canceling the underlying future. /// /// This method can be used if you want to drop the handle, but let the @@ -30,7 +39,7 @@ impl JoinHandle { } } -impl Future for JoinHandle { +impl Future for RemoteHandle { type Output = T; fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { @@ -43,21 +52,34 @@ impl Future for JoinHandle { } } -struct Wrapped { - tx: Option>, +type SendMsg = Result<::Output, Box<(dyn Any + Send + 'static)>>; + +/// A future which sends its output to the corresponding `RemoteHandle`. +/// Created by [`remote_handle`](crate::future::FutureExt::remote_handle). +#[must_use = "futures do nothing unless polled"] +pub struct Remote { + tx: Option>>, keep_running: Arc, - future: Fut, + future: CatchUnwind>, } -impl Unpin for Wrapped {} +impl fmt::Debug for Remote { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Remote") + .field(&self.future) + .finish() + } +} + +impl Unpin for Remote {} -impl Wrapped { - unsafe_pinned!(future: Fut); - unsafe_unpinned!(tx: Option>); +impl Remote { + unsafe_pinned!(future: CatchUnwind>); + unsafe_unpinned!(tx: Option>>); unsafe_unpinned!(keep_running: Arc); } -impl Future for Wrapped { +impl Future for Remote { type Output = (); fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { @@ -80,29 +102,18 @@ impl Future for Wrapped { } } -pub(super) fn spawn_with_handle( - executor: &mut Sp, - future: Fut, -) -> Result, SpawnError> -where Sp: Spawn + ?Sized, - Fut: Future + Send + 'static, - Fut::Output: Send, -{ +pub(super) fn remote_handle(future: Fut) -> (Remote, RemoteHandle) { let (tx, rx) = oneshot::channel(); let keep_running = Arc::new(AtomicBool::new(false)); // AssertUnwindSafe is used here because `Send + 'static` is basically // an alias for an implementation of the `UnwindSafe` trait but we can't // express that in the standard library right now. - let wrapped = Wrapped { + let wrapped = Remote { future: AssertUnwindSafe(future).catch_unwind(), tx: Some(tx), keep_running: keep_running.clone(), }; - let res = executor.spawn_obj(Box::new(wrapped).into()); - match res { - Ok(()) => Ok(JoinHandle { rx, keep_running }), - Err(SpawnObjError { kind, .. }) => Err(SpawnError { kind }), - } + (wrapped, RemoteHandle { rx, keep_running }) } diff --git a/futures-util/src/future/shared.rs b/futures-util/src/future/shared.rs index 78aa58e2f3..b6d64107e9 100644 --- a/futures-util/src/future/shared.rs +++ b/futures-util/src/future/shared.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll, Wake, Waker}; +use futures_core::task::{LocalWaker, Poll, Wake, Waker}; use slab::Slab; use std::fmt; use std::cell::UnsafeCell; @@ -116,18 +116,18 @@ where return }; if self.waker_key == NULL_WAKER_KEY { - self.waker_key = wakers.insert(Some(lw.waker().clone())); + self.waker_key = wakers.insert(Some(lw.clone().into_waker())); } else { let waker_slot = &mut wakers[self.waker_key]; let needs_replacement = if let Some(old_waker) = waker_slot { // If there's still an unwoken waker in the slot, only replace // if the current one wouldn't wake the same task. - !old_waker.will_wake(lw.waker()) + !lw.will_wake_nonlocal(old_waker) } else { true }; if needs_replacement { - *waker_slot = Some(lw.waker().clone()); + *waker_slot = Some(lw.clone().into_waker()); } } debug_assert!(self.waker_key != NULL_WAKER_KEY); @@ -173,7 +173,7 @@ where } let waker = local_waker_from_nonlocal(this.inner.notifier.clone()); - let mut lw = lw.with_waker(&waker); + let lw = &waker; loop { struct Reset<'a>(&'a AtomicUsize); @@ -193,7 +193,7 @@ where // Poll the future let res = unsafe { if let FutureOrOutput::Future(future) = &mut *this.inner.future_or_output.get() { - Pin::new_unchecked(future).poll(&mut lw) + Pin::new_unchecked(future).poll(lw) } else { unreachable!() } diff --git a/futures-util/src/future/then.rs b/futures-util/src/future/then.rs index 1e54a40da5..5eedef57d5 100644 --- a/futures-util/src/future/then.rs +++ b/futures-util/src/future/then.rs @@ -1,7 +1,7 @@ use super::Chain; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the `then` combinator, chaining computations on the end of diff --git a/futures-util/src/future/unit_error.rs b/futures-util/src/future/unit_error.rs index 6fd6fe1922..478a2ca645 100644 --- a/futures-util/src/future/unit_error.rs +++ b/futures-util/src/future/unit_error.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the `unit_error` combinator, turning a `Future` into a `TryFuture`. diff --git a/futures-util/src/future/with_spawner.rs b/futures-util/src/future/with_spawner.rs index 04bf57b4a5..57cc477de3 100644 --- a/futures-util/src/future/with_spawner.rs +++ b/futures-util/src/future/with_spawner.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll, Spawn}; +use futures_core::task::{LocalWaker, Poll, Spawn}; /// Future for the `with_spawner` combinator, assigning a [`Spawn`] /// to be used when spawning other futures. diff --git a/futures-util/src/io/allow_std.rs b/futures-util/src/io/allow_std.rs index 12eff3704e..2dbb9f4405 100644 --- a/futures-util/src/io/allow_std.rs +++ b/futures-util/src/io/allow_std.rs @@ -1,4 +1,4 @@ -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::{AsyncRead, AsyncWrite}; use std::{fmt, io}; use std::string::String; diff --git a/futures-util/src/io/close.rs b/futures-util/src/io/close.rs index 35482fa889..965f05f22a 100644 --- a/futures-util/src/io/close.rs +++ b/futures-util/src/io/close.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::AsyncWrite; use std::io; use std::marker::Unpin; diff --git a/futures-util/src/io/copy_into.rs b/futures-util/src/io/copy_into.rs index d0f8def4dc..49f24713a5 100644 --- a/futures-util/src/io/copy_into.rs +++ b/futures-util/src/io/copy_into.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::{AsyncRead, AsyncWrite}; use std::boxed::Box; use std::io; diff --git a/futures-util/src/io/flush.rs b/futures-util/src/io/flush.rs index 69aa7e0b5e..ea88943976 100644 --- a/futures-util/src/io/flush.rs +++ b/futures-util/src/io/flush.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use std::io; use std::marker::Unpin; use std::pin::Pin; diff --git a/futures-util/src/io/read.rs b/futures-util/src/io/read.rs index b485dab1be..d1c986298c 100644 --- a/futures-util/src/io/read.rs +++ b/futures-util/src/io/read.rs @@ -1,6 +1,6 @@ use crate::io::AsyncRead; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use std::io; use std::marker::Unpin; use std::pin::Pin; diff --git a/futures-util/src/io/read_exact.rs b/futures-util/src/io/read_exact.rs index c9b392efe8..ec762b9a5e 100644 --- a/futures-util/src/io/read_exact.rs +++ b/futures-util/src/io/read_exact.rs @@ -1,6 +1,6 @@ use crate::io::AsyncRead; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use std::io; use std::marker::Unpin; use std::mem; diff --git a/futures-util/src/io/read_to_end.rs b/futures-util/src/io/read_to_end.rs index 288c4adf7f..44970dba81 100644 --- a/futures-util/src/io/read_to_end.rs +++ b/futures-util/src/io/read_to_end.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::AsyncRead; use std::io; use std::marker::Unpin; diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index 003360bf6c..18c4330106 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -1,5 +1,5 @@ use crate::lock::BiLock; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::{AsyncRead, AsyncWrite, IoVec}; use std::io; use std::pin::Pin; diff --git a/futures-util/src/io/write_all.rs b/futures-util/src/io/write_all.rs index 281fe5b501..43290a1a34 100644 --- a/futures-util/src/io/write_all.rs +++ b/futures-util/src/io/write_all.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_io::AsyncWrite; use std::io; use std::marker::Unpin; diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index b3d15b2a7a..e3d2f74c71 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -37,7 +37,7 @@ macro_rules! delegate_sink { ($field:ident) => { fn poll_ready( mut self: Pin<&mut Self>, - lw: &mut $crate::core_reexport::task::Context, + lw: &$crate::core_reexport::task::LocalWaker, ) -> $crate::core_reexport::task::Poll> { self.$field().poll_ready(lw) } @@ -51,14 +51,14 @@ macro_rules! delegate_sink { fn poll_flush( mut self: Pin<&mut Self>, - lw: &mut $crate::core_reexport::task::Context + lw: &$crate::core_reexport::task::LocalWaker ) -> $crate::core_reexport::task::Poll> { self.$field().poll_flush(lw) } fn poll_close( mut self: Pin<&mut Self>, - lw: &mut $crate::core_reexport::task::Context + lw: &$crate::core_reexport::task::LocalWaker ) -> $crate::core_reexport::task::Poll> { self.$field().poll_close(lw) } diff --git a/futures-util/src/lock.rs b/futures-util/src/lock.rs index 42a7baa353..a61b1c7fae 100644 --- a/futures-util/src/lock.rs +++ b/futures-util/src/lock.rs @@ -2,7 +2,7 @@ #![allow(unused)] use futures_core::future::Future; -use futures_core::task::{self, Poll, Waker}; +use futures_core::task::{LocalWaker, Poll, Waker}; use std::any::Any; use std::boxed::Box; use std::cell::UnsafeCell; @@ -104,7 +104,7 @@ impl BiLock { } // type ascription for safety's sake! - let me: Box = Box::new(lw.waker().clone()); + let me: Box = Box::new(lw.clone().into_waker()); let me = Box::into_raw(me) as usize; match self.arc.state.compare_exchange(1, me, SeqCst, SeqCst) { diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index 0df07b4f52..fced850026 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -1,5 +1,5 @@ use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::collections::VecDeque; diff --git a/futures-util/src/sink/close.rs b/futures-util/src/sink/close.rs index 5793411769..30f582963e 100644 --- a/futures-util/src/sink/close.rs +++ b/futures-util/src/sink/close.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; /// Future for the `close` combinator, which polls the sink until all data has diff --git a/futures-util/src/sink/drain.rs b/futures-util/src/sink/drain.rs index ae947283d1..e65ed45ed0 100644 --- a/futures-util/src/sink/drain.rs +++ b/futures-util/src/sink/drain.rs @@ -1,7 +1,7 @@ use core::fmt; use core::marker::PhantomData; use core::pin::Pin; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; /// A sink that will discard all items given to it. diff --git a/futures-util/src/sink/err_into.rs b/futures-util/src/sink/err_into.rs index a160f26e08..8205c72e74 100644 --- a/futures-util/src/sink/err_into.rs +++ b/futures-util/src/sink/err_into.rs @@ -1,7 +1,7 @@ use crate::sink::{SinkExt, SinkMapErr}; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::{Sink}; use pin_utils::unsafe_pinned; diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index eb7a39c71b..6b9a8443f1 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -1,6 +1,6 @@ use core::fmt::{Debug, Formatter, Result as FmtResult}; use core::pin::Pin; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::unsafe_pinned; diff --git a/futures-util/src/sink/flush.rs b/futures-util/src/sink/flush.rs index 5478043363..03209e1031 100644 --- a/futures-util/src/sink/flush.rs +++ b/futures-util/src/sink/flush.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; /// Future for the `flush` combinator, which polls the sink until all data diff --git a/futures-util/src/sink/map_err.rs b/futures-util/src/sink/map_err.rs index 6200150749..7dab01eacb 100644 --- a/futures-util/src/sink/map_err.rs +++ b/futures-util/src/sink/map_err.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::{Sink}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; diff --git a/futures-util/src/sink/send.rs b/futures-util/src/sink/send.rs index e7e2708ff3..535e95b5a7 100644 --- a/futures-util/src/sink/send.rs +++ b/futures-util/src/sink/send.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; /// Future for the `Sink::send` combinator, which sends a value to a sink and diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index 83eb6158c2..d78a4cab9c 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -3,7 +3,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; /// Future for the `Sink::send_all` combinator, which sends a stream of values diff --git a/futures-util/src/sink/with.rs b/futures-util/src/sink/with.rs index 2a69397966..0b22a4b635 100644 --- a/futures-util/src/sink/with.rs +++ b/futures-util/src/sink/with.rs @@ -3,7 +3,7 @@ use core::mem; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 6e25c55054..b74f0d24ae 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -1,7 +1,7 @@ use core::marker::{Unpin, PhantomData}; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; diff --git a/futures-util/src/stream/buffer_unordered.rs b/futures-util/src/stream/buffer_unordered.rs index cfb1287ce3..76de06c36c 100644 --- a/futures-util/src/stream/buffer_unordered.rs +++ b/futures-util/src/stream/buffer_unordered.rs @@ -1,7 +1,7 @@ use crate::stream::{Fuse, FuturesUnordered}; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::fmt; diff --git a/futures-util/src/stream/buffered.rs b/futures-util/src/stream/buffered.rs index 22c1c10358..735499898c 100644 --- a/futures-util/src/stream/buffered.rs +++ b/futures-util/src/stream/buffered.rs @@ -1,7 +1,7 @@ use crate::stream::{Fuse, FuturesOrdered}; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::fmt; diff --git a/futures-util/src/stream/catch_unwind.rs b/futures-util/src/stream/catch_unwind.rs index 3d8cfa722b..837c55cfa0 100644 --- a/futures-util/src/stream/catch_unwind.rs +++ b/futures-util/src/stream/catch_unwind.rs @@ -1,5 +1,5 @@ use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::any::Any; use std::pin::Pin; diff --git a/futures-util/src/stream/chain.rs b/futures-util/src/stream/chain.rs index e357c757c7..c451c5eda7 100644 --- a/futures-util/src/stream/chain.rs +++ b/futures-util/src/stream/chain.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// An adapter for chaining the output of two streams. diff --git a/futures-util/src/stream/chunks.rs b/futures-util/src/stream/chunks.rs index 52b4e7da50..d79de2179e 100644 --- a/futures-util/src/stream/chunks.rs +++ b/futures-util/src/stream/chunks.rs @@ -1,6 +1,6 @@ use crate::stream::Fuse; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; diff --git a/futures-util/src/stream/collect.rs b/futures-util/src/stream/collect.rs index 74878af581..73be32e162 100644 --- a/futures-util/src/stream/collect.rs +++ b/futures-util/src/stream/collect.rs @@ -1,6 +1,6 @@ use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; diff --git a/futures-util/src/stream/concat.rs b/futures-util/src/stream/concat.rs index 7797673fbf..202a0f6f30 100644 --- a/futures-util/src/stream/concat.rs +++ b/futures-util/src/stream/concat.rs @@ -4,7 +4,7 @@ use core::pin::Pin; use core::default::Default; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator to concatenate the results of a stream into the first diff --git a/futures-util/src/stream/empty.rs b/futures-util/src/stream/empty.rs index 031bae4312..4ea9b4a78b 100644 --- a/futures-util/src/stream/empty.rs +++ b/futures-util/src/stream/empty.rs @@ -1,7 +1,7 @@ use core::marker::{Unpin, PhantomData}; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A stream which contains no elements. /// diff --git a/futures-util/src/stream/filter.rs b/futures-util/src/stream/filter.rs index 07fffaeae4..ccefe08b5a 100644 --- a/futures-util/src/stream/filter.rs +++ b/futures-util/src/stream/filter.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator used to filter the results of a stream and only yield diff --git a/futures-util/src/stream/filter_map.rs b/futures-util/src/stream/filter_map.rs index 2520483a54..0b904f4b39 100644 --- a/futures-util/src/stream/filter_map.rs +++ b/futures-util/src/stream/filter_map.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A combinator used to filter the results of a stream and simultaneously map diff --git a/futures-util/src/stream/flatten.rs b/futures-util/src/stream/flatten.rs index c73d9a58ed..144a4f1669 100644 --- a/futures-util/src/stream/flatten.rs +++ b/futures-util/src/stream/flatten.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// A combinator used to flatten a stream-of-streams into one long stream of diff --git a/futures-util/src/stream/fold.rs b/futures-util/src/stream/fold.rs index 0fbf7e2a3a..cb3135b7ea 100644 --- a/futures-util/src/stream/fold.rs +++ b/futures-util/src/stream/fold.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A future used to collect all the results of a stream into one generic type. diff --git a/futures-util/src/stream/for_each.rs b/futures-util/src/stream/for_each.rs index c853e678f9..efc6425d35 100644 --- a/futures-util/src/stream/for_each.rs +++ b/futures-util/src/stream/for_each.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which executes a unit closure over each item on a diff --git a/futures-util/src/stream/for_each_concurrent.rs b/futures-util/src/stream/for_each_concurrent.rs index 477419a2ce..0680643fa0 100644 --- a/futures-util/src/stream/for_each_concurrent.rs +++ b/futures-util/src/stream/for_each_concurrent.rs @@ -4,7 +4,7 @@ use core::pin::Pin; use core::num::NonZeroUsize; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which executes a unit closure over each item on a diff --git a/futures-util/src/stream/forward.rs b/futures-util/src/stream/forward.rs index bd741f4d28..f4058f756d 100644 --- a/futures-util/src/stream/forward.rs +++ b/futures-util/src/stream/forward.rs @@ -3,7 +3,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; diff --git a/futures-util/src/stream/fuse.rs b/futures-util/src/stream/fuse.rs index b6b03481bd..aec1f4c901 100644 --- a/futures-util/src/stream/fuse.rs +++ b/futures-util/src/stream/fuse.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use pin_utils::{unsafe_pinned, unsafe_unpinned}; diff --git a/futures-util/src/stream/futures_ordered.rs b/futures-util/src/stream/futures_ordered.rs index 33f24c8b2f..2915a9e703 100644 --- a/futures-util/src/stream/futures_ordered.rs +++ b/futures-util/src/stream/futures_ordered.rs @@ -1,7 +1,7 @@ use crate::stream::FuturesUnordered; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; use std::cmp::{Eq, PartialEq, PartialOrd, Ord, Ordering}; use std::collections::binary_heap::{BinaryHeap, PeekMut}; diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index 194f5b52d2..933901a225 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -3,7 +3,7 @@ use crate::task::AtomicWaker; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self as core_task, Poll}; +use futures_core::task::{LocalWaker, Poll}; use std::cell::UnsafeCell; use std::fmt::{self, Debug}; use std::iter::FromIterator; @@ -254,11 +254,11 @@ impl FuturesUnordered { impl Stream for FuturesUnordered { type Item = Fut::Output; - fn poll_next(mut self: Pin<&mut Self>, lw: &mut core_task::Context) + fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { // Ensure `parent` is correctly set. - self.ready_to_run_queue.waker.register(lw.waker()); + self.ready_to_run_queue.waker.register(lw); loop { // Safety: &mut self guarantees the mutual exclusion `dequeue` @@ -275,7 +275,7 @@ impl Stream for FuturesUnordered { // At this point, it may be worth yielding the thread & // spinning a few times... but for now, just yield using the // task system. - lw.local_waker().wake(); + lw.wake(); return Poll::Pending; } Dequeue::Data(task) => task, @@ -366,13 +366,12 @@ impl Stream for FuturesUnordered { // the internal allocation, appropriately accessing fields and // deallocating the task if need be. let res = { - let local_waker = bomb.task.as_ref().unwrap().local_waker(); - let mut lw = lw.with_waker(&*local_waker); + let lw = bomb.task.as_ref().unwrap().local_waker(); // Safety: We won't move the future ever again let future = unsafe { Pin::new_unchecked(future) }; - future.poll(&mut lw) + future.poll(&lw) }; match res { diff --git a/futures-util/src/stream/inspect.rs b/futures-util/src/stream/inspect.rs index f845df7844..13ba1be3ed 100644 --- a/futures-util/src/stream/inspect.rs +++ b/futures-util/src/stream/inspect.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Do something with the items of a stream, passing it on. diff --git a/futures-util/src/stream/into_future.rs b/futures-util/src/stream/into_future.rs index 9337ac7a7c..9a7bd15756 100644 --- a/futures-util/src/stream/into_future.rs +++ b/futures-util/src/stream/into_future.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A combinator used to temporarily convert a stream into a future. /// diff --git a/futures-util/src/stream/iter.rs b/futures-util/src/stream/iter.rs index 56456c2ef4..9b293adb62 100644 --- a/futures-util/src/stream/iter.rs +++ b/futures-util/src/stream/iter.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A stream which is just a shim over an underlying instance of `Iterator`. /// diff --git a/futures-util/src/stream/map.rs b/futures-util/src/stream/map.rs index 84be4152ef..7c40e54fa9 100644 --- a/futures-util/src/stream/map.rs +++ b/futures-util/src/stream/map.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which will change the type of a stream from one diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index e98bc7aa44..51cb14589c 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -8,7 +8,7 @@ use core::pin::Pin; use either::Either; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; mod iter; diff --git a/futures-util/src/stream/next.rs b/futures-util/src/stream/next.rs index 662d64959b..7c2dc5b880 100644 --- a/futures-util/src/stream/next.rs +++ b/futures-util/src/stream/next.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A future of the next element of a stream. #[derive(Debug)] diff --git a/futures-util/src/stream/once.rs b/futures-util/src/stream/once.rs index 737828d945..a7a34ea2a5 100644 --- a/futures-util/src/stream/once.rs +++ b/futures-util/src/stream/once.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Creates a stream of single element diff --git a/futures-util/src/stream/peek.rs b/futures-util/src/stream/peek.rs index 40f711d0da..80626af9fc 100644 --- a/futures-util/src/stream/peek.rs +++ b/futures-util/src/stream/peek.rs @@ -2,7 +2,7 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A `Stream` that implements a `peek` method. diff --git a/futures-util/src/stream/poll_fn.rs b/futures-util/src/stream/poll_fn.rs index 7b0588beb3..bb4e2231c6 100644 --- a/futures-util/src/stream/poll_fn.rs +++ b/futures-util/src/stream/poll_fn.rs @@ -3,7 +3,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// A stream which adapts a function returning `Poll`. /// diff --git a/futures-util/src/stream/repeat.rs b/futures-util/src/stream/repeat.rs index 6b2a13360d..5d9e00f6d3 100644 --- a/futures-util/src/stream/repeat.rs +++ b/futures-util/src/stream/repeat.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// Stream that produces the same element repeatedly. /// diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index d00072d371..d98ece3ae9 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -2,7 +2,7 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; /// An adapter for merging the output of two streams. /// diff --git a/futures-util/src/stream/skip.rs b/futures-util/src/stream/skip.rs index 9414b362fe..df522783b9 100644 --- a/futures-util/src/stream/skip.rs +++ b/futures-util/src/stream/skip.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which skips a number of elements before continuing. diff --git a/futures-util/src/stream/skip_while.rs b/futures-util/src/stream/skip_while.rs index 01ae7eb41b..1c2c61ad62 100644 --- a/futures-util/src/stream/skip_while.rs +++ b/futures-util/src/stream/skip_while.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which skips elements of a stream while a predicate diff --git a/futures-util/src/stream/split.rs b/futures-util/src/stream/split.rs index 079027c71c..ef82a9d8be 100644 --- a/futures-util/src/stream/split.rs +++ b/futures-util/src/stream/split.rs @@ -1,5 +1,5 @@ use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; use std::any::Any; use std::error::Error; diff --git a/futures-util/src/stream/take.rs b/futures-util/src/stream/take.rs index c3db35adbf..6ad7f19866 100644 --- a/futures-util/src/stream/take.rs +++ b/futures-util/src/stream/take.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which returns a maximum number of elements. diff --git a/futures-util/src/stream/take_while.rs b/futures-util/src/stream/take_while.rs index c21f3afd1b..12e2974ac4 100644 --- a/futures-util/src/stream/take_while.rs +++ b/futures-util/src/stream/take_while.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which takes elements from a stream while a predicate diff --git a/futures-util/src/stream/then.rs b/futures-util/src/stream/then.rs index fbcd4c966c..edee04ba63 100644 --- a/futures-util/src/stream/then.rs +++ b/futures-util/src/stream/then.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which chains a computation onto each item produced by a diff --git a/futures-util/src/stream/unfold.rs b/futures-util/src/stream/unfold.rs index a619b9c406..19d343f23b 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::Future; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Creates a `Stream` from a seed and a closure returning a `Future`. diff --git a/futures-util/src/stream/zip.rs b/futures-util/src/stream/zip.rs index 5825ce611c..40a024e40f 100644 --- a/futures-util/src/stream/zip.rs +++ b/futures-util/src/stream/zip.rs @@ -2,7 +2,7 @@ use crate::stream::{StreamExt, Fuse}; use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::Stream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// An adapter for merging the output of two streams. diff --git a/futures-util/src/task/atomic_waker.rs b/futures-util/src/task/atomic_waker.rs index d1dc684c5e..f5defe7c78 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-util/src/task/atomic_waker.rs @@ -2,7 +2,7 @@ use core::fmt; use core::cell::UnsafeCell; use core::sync::atomic::AtomicUsize; use core::sync::atomic::Ordering::{Acquire, Release, AcqRel}; -use futures_core::task::Waker; +use futures_core::task::{LocalWaker, Waker}; /// A synchronization primitive for task wakeup. /// @@ -171,7 +171,7 @@ impl AtomicWaker { /// ``` /// #![feature(pin, arbitrary_self_types, futures_api)] /// use futures::future::Future; - /// use futures::task::{self, Poll, AtomicWaker}; + /// use futures::task::{LocalWaker, Poll, AtomicWaker}; /// use std::sync::atomic::AtomicBool; /// use std::sync::atomic::Ordering::SeqCst; /// use std::pin::Pin; @@ -197,12 +197,12 @@ impl AtomicWaker { /// } /// } /// ``` - pub fn register(&self, waker: &Waker) { + pub fn register(&self, lw: &LocalWaker) { match self.state.compare_and_swap(WAITING, REGISTERING, Acquire) { WAITING => { unsafe { // Locked acquired, update the waker cell - *self.waker.get() = Some(waker.clone()); + *self.waker.get() = Some(lw.clone().into_waker()); // Release the lock. If the state transitioned to include // the `WAKING` bit, this means that a wake has been @@ -253,7 +253,7 @@ impl AtomicWaker { // Currently in the process of waking the task, i.e., // `wake` is currently being called on the old task handle. // So, we call wake on the new waker - waker.wake(); + lw.wake(); } state => { // In this case, a concurrent thread is holding the diff --git a/futures-util/src/task/mod.rs b/futures-util/src/task/mod.rs index 1ac08222c0..6bf692ab92 100644 --- a/futures-util/src/task/mod.rs +++ b/futures-util/src/task/mod.rs @@ -1,11 +1,6 @@ //! Task notification -mod spawn; -pub use self::spawn::{SpawnExt, SpawnError}; - if_std! { - pub use self::spawn::JoinHandle; - mod local_waker_ref; pub use self::local_waker_ref::{local_waker_ref, local_waker_ref_from_nonlocal, LocalWakerRef}; } diff --git a/futures-util/src/task/spawn/mod.rs b/futures-util/src/task/spawn/mod.rs deleted file mode 100644 index c8970c8505..0000000000 --- a/futures-util/src/task/spawn/mod.rs +++ /dev/null @@ -1,85 +0,0 @@ -use futures_core::task::Spawn; - -mod spawn_error; -pub use self::spawn_error::SpawnError; - -if_std! { - use futures_core::future::Future; - - mod spawn_with_handle; - use self::spawn_with_handle::spawn_with_handle; - pub use self::spawn_with_handle::JoinHandle; -} - -impl SpawnExt for Sp where Sp: Spawn {} - -/// Extension trait for `Spawn` -pub trait SpawnExt: Spawn { - /// Spawns a task that polls the given future with output `()` to - /// completion. - /// - /// This method returns a [`Result`] that contains a [`SpawnError`] if - /// spawning fails. - /// - /// You can use [`spawn_with_handle`](SpawnExt::spawn_with_handle) if - /// you want to spawn a future with output other than `()` or if you want - /// to be able to await its completion. - /// - /// Note this method will eventually be replaced with the upcoming - /// `Spawn::spawn` method which will take a `dyn Future` as input. - /// Technical limitations prevent `Spawn::spawn` from being implemented - /// today. Feel free to use this method in the meantime. - /// - /// ``` - /// #![feature(async_await, await_macro, futures_api)] - /// # futures::executor::block_on(async { - /// use futures::executor::ThreadPool; - /// use futures::task::SpawnExt; - /// - /// let mut executor = ThreadPool::new().unwrap(); - /// - /// let future = async { /* ... */ }; - /// executor.spawn(future).unwrap(); - /// # }); - /// ``` - #[cfg(feature = "std")] - fn spawn(&mut self, future: Fut) -> Result<(), SpawnError> - where Fut: Future + Send + 'static, - { - let res = self.spawn_obj(Box::new(future).into()); - res.map_err(|err| SpawnError { kind: err.kind }) - } - - /// Spawns a task that polls the given future to completion and returns a - /// future that resolves to the spawned future's output. - /// - /// This method returns a [`Result`] that contains a [`JoinHandle`], or, if - /// spawning fails, a [`SpawnError`]. [`JoinHandle`] is a future that - /// resolves to the output of the spawned future. - /// - /// ``` - /// #![feature(async_await, await_macro, futures_api)] - /// # futures::executor::block_on(async { - /// use futures::executor::ThreadPool; - /// use futures::future; - /// use futures::task::SpawnExt; - /// - /// let mut executor = ThreadPool::new().unwrap(); - /// - /// let future = future::ready(1); - /// let join_handle = executor.spawn_with_handle(future).unwrap(); - /// assert_eq!(await!(join_handle), 1); - /// # }); - /// ``` - #[cfg(feature = "std")] - fn spawn_with_handle( - &mut self, - future: Fut - ) -> Result, SpawnError> - where Fut: Future + Send + 'static, - Fut::Output: Send, - { - spawn_with_handle(self, future) - } -} - diff --git a/futures-util/src/task/spawn/spawn_error.rs b/futures-util/src/task/spawn/spawn_error.rs deleted file mode 100644 index 211bc6bdd4..0000000000 --- a/futures-util/src/task/spawn/spawn_error.rs +++ /dev/null @@ -1,8 +0,0 @@ -use futures_core::task::SpawnErrorKind; - -/// The result of a failed spawn -#[derive(Debug)] -pub struct SpawnError { - /// The kind of error - pub kind: SpawnErrorKind, -} diff --git a/futures-util/src/try_future/and_then.rs b/futures-util/src/try_future/and_then.rs index 47b061ee1f..e1fa58660d 100644 --- a/futures-util/src/try_future/and_then.rs +++ b/futures-util/src/try_future/and_then.rs @@ -1,7 +1,7 @@ use super::{TryChain, TryChainAction}; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the [`and_then`](super::TryFutureExt::and_then) combinator. diff --git a/futures-util/src/try_future/err_into.rs b/futures-util/src/try_future/err_into.rs index 95f3d70505..99a8f19f55 100644 --- a/futures-util/src/try_future/err_into.rs +++ b/futures-util/src/try_future/err_into.rs @@ -1,7 +1,7 @@ use core::marker::{PhantomData, Unpin}; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the [`err_into`](super::TryFutureExt::err_into) combinator. diff --git a/futures-util/src/try_future/flatten_sink.rs b/futures-util/src/try_future/flatten_sink.rs index 2a04367144..0295e18099 100644 --- a/futures-util/src/try_future/flatten_sink.rs +++ b/futures-util/src/try_future/flatten_sink.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::TryFuture; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use futures_sink::Sink; #[derive(Debug)] diff --git a/futures-util/src/try_future/into_future.rs b/futures-util/src/try_future/into_future.rs index 23c72059d5..faa900f888 100644 --- a/futures-util/src/try_future/into_future.rs +++ b/futures-util/src/try_future/into_future.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the [`into_future`](super::TryFutureExt::into_future) combinator. diff --git a/futures-util/src/try_future/map_err.rs b/futures-util/src/try_future/map_err.rs index a86c5111c9..938c7259d5 100644 --- a/futures-util/src/try_future/map_err.rs +++ b/futures-util/src/try_future/map_err.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Future for the [`map_err`](super::TryFutureExt::map_err) combinator. diff --git a/futures-util/src/try_future/map_ok.rs b/futures-util/src/try_future/map_ok.rs index 719aae2aad..247209928a 100644 --- a/futures-util/src/try_future/map_ok.rs +++ b/futures-util/src/try_future/map_ok.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Future for the [`map_ok`](super::TryFutureExt::map_ok) combinator. diff --git a/futures-util/src/try_future/or_else.rs b/futures-util/src/try_future/or_else.rs index 6629745172..b554b7d5e3 100644 --- a/futures-util/src/try_future/or_else.rs +++ b/futures-util/src/try_future/or_else.rs @@ -1,7 +1,7 @@ use super::{TryChain, TryChainAction}; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Future for the [`or_else`](super::TryFutureExt::or_else) combinator. diff --git a/futures-util/src/try_future/try_chain.rs b/futures-util/src/try_future/try_chain.rs index 77f52a9f96..025b2be6a9 100644 --- a/futures-util/src/try_future/try_chain.rs +++ b/futures-util/src/try_future/try_chain.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::future::TryFuture; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; #[must_use = "futures do nothing unless polled"] #[derive(Debug)] diff --git a/futures-util/src/try_future/try_join.rs b/futures-util/src/try_future/try_join.rs index d1ada08cc8..4c5bd43562 100644 --- a/futures-util/src/try_future/try_join.rs +++ b/futures-util/src/try_future/try_join.rs @@ -5,7 +5,7 @@ use crate::try_future::{TryFutureExt, IntoFuture}; use core::fmt; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; macro_rules! generate { diff --git a/futures-util/src/try_future/unwrap_or_else.rs b/futures-util/src/try_future/unwrap_or_else.rs index 7f612d4221..61f79c71ec 100644 --- a/futures-util/src/try_future/unwrap_or_else.rs +++ b/futures-util/src/try_future/unwrap_or_else.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Future for the [`unwrap_or_else`](super::TryFutureExt::unwrap_or_else) diff --git a/futures-util/src/try_stream/err_into.rs b/futures-util/src/try_stream/err_into.rs index aadd27b507..b9759aaac1 100644 --- a/futures-util/src/try_stream/err_into.rs +++ b/futures-util/src/try_stream/err_into.rs @@ -1,7 +1,7 @@ use core::marker::{PhantomData, Unpin}; use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Stream for the [`err_into`](super::TryStreamExt::err_into) combinator. diff --git a/futures-util/src/try_stream/into_stream.rs b/futures-util/src/try_stream/into_stream.rs index 33efb03ce2..54abe6882a 100644 --- a/futures-util/src/try_stream/into_stream.rs +++ b/futures-util/src/try_stream/into_stream.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; /// Stream for the [`into_stream`](super::TryStreamExt::into_stream) combinator. diff --git a/futures-util/src/try_stream/map_err.rs b/futures-util/src/try_stream/map_err.rs index 89cdad0759..febc052246 100644 --- a/futures-util/src/try_stream/map_err.rs +++ b/futures-util/src/try_stream/map_err.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Stream for the [`map_err`](super::TryStreamExt::map_err) combinator. diff --git a/futures-util/src/try_stream/map_ok.rs b/futures-util/src/try_stream/map_ok.rs index 465f7ac3bf..3a15fd253e 100644 --- a/futures-util/src/try_stream/map_ok.rs +++ b/futures-util/src/try_stream/map_ok.rs @@ -1,7 +1,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// Stream for the [`map_ok`](super::TryStreamExt::map_ok) combinator. diff --git a/futures-util/src/try_stream/try_buffer_unordered.rs b/futures-util/src/try_stream/try_buffer_unordered.rs index 8a769e9ac7..638962a7b5 100644 --- a/futures-util/src/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/try_stream/try_buffer_unordered.rs @@ -3,7 +3,7 @@ use crate::try_future::{IntoFuture, TryFutureExt}; use crate::try_stream::IntoStream; use futures_core::future::TryFuture; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::pin::Pin; diff --git a/futures-util/src/try_stream/try_collect.rs b/futures-util/src/try_stream/try_collect.rs index 74260fdc34..a47c4b5e93 100644 --- a/futures-util/src/try_stream/try_collect.rs +++ b/futures-util/src/try_stream/try_collect.rs @@ -1,6 +1,6 @@ use futures_core::future::Future; use futures_core::stream::TryStream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Unpin; use std::mem; diff --git a/futures-util/src/try_stream/try_filter_map.rs b/futures-util/src/try_stream/try_filter_map.rs index 5c70a61062..f515373ae7 100644 --- a/futures-util/src/try_stream/try_filter_map.rs +++ b/futures-util/src/try_stream/try_filter_map.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{TryFuture}; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A combinator that attempts to filter the results of a stream diff --git a/futures-util/src/try_stream/try_fold.rs b/futures-util/src/try_stream/try_fold.rs index dd52e0ec15..4519aa61d3 100644 --- a/futures-util/src/try_stream/try_fold.rs +++ b/futures-util/src/try_stream/try_fold.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::stream::TryStream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// The future for the `TryStream::fold` method. diff --git a/futures-util/src/try_stream/try_for_each.rs b/futures-util/src/try_stream/try_for_each.rs index 5a06308ce8..fcc4676165 100644 --- a/futures-util/src/try_stream/try_for_each.rs +++ b/futures-util/src/try_stream/try_for_each.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::stream::TryStream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which attempts to execute an async closure over each 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 82200a4137..367de2222b 100644 --- a/futures-util/src/try_stream/try_for_each_concurrent.rs +++ b/futures-util/src/try_stream/try_for_each_concurrent.rs @@ -4,7 +4,7 @@ use core::pin::Pin; use core::num::NonZeroUsize; use futures_core::future::Future; use futures_core::stream::TryStream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which executes a unit closure over each item on a diff --git a/futures-util/src/try_stream/try_next.rs b/futures-util/src/try_stream/try_next.rs index a6b21b0093..406d35cd2a 100644 --- a/futures-util/src/try_stream/try_next.rs +++ b/futures-util/src/try_stream/try_next.rs @@ -1,6 +1,6 @@ use futures_core::future::Future; use futures_core::stream::TryStream; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use core::marker::Unpin; use core::pin::Pin; diff --git a/futures-util/src/try_stream/try_skip_while.rs b/futures-util/src/try_stream/try_skip_while.rs index 4705e1ce8d..15d30e0fb1 100644 --- a/futures-util/src/try_stream/try_skip_while.rs +++ b/futures-util/src/try_stream/try_skip_while.rs @@ -2,7 +2,7 @@ use core::marker::Unpin; use core::pin::Pin; use futures_core::future::TryFuture; use futures_core::stream::{Stream, TryStream}; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// A stream combinator which skips elements of a stream while a predicate From 9e873ee18df735c671cbe67266428500320a92c7 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Fri, 28 Sep 2018 15:39:19 -0700 Subject: [PATCH 07/14] Update to new Spawn and LocalSpawn traits --- futures-core/src/{task.rs => task/mod.rs} | 3 + futures-core/src/task/spawn.rs | 79 +++++++++++++++++++ futures-executor/src/lib.rs | 2 +- futures-executor/src/local_pool.rs | 59 ++++++-------- futures-executor/src/thread_pool.rs | 11 +-- futures-util/src/async_await/mod.rs | 4 - futures-util/src/async_await/spawn.rs | 58 -------------- .../src/stream/futures_unordered/mod.rs | 22 +++++- futures/src/lib.rs | 32 +++----- 9 files changed, 143 insertions(+), 127 deletions(-) rename futures-core/src/{task.rs => task/mod.rs} (71%) create mode 100644 futures-core/src/task/spawn.rs delete mode 100644 futures-util/src/async_await/spawn.rs diff --git a/futures-core/src/task.rs b/futures-core/src/task/mod.rs similarity index 71% rename from futures-core/src/task.rs rename to futures-core/src/task/mod.rs index b1fe40d285..b01ea1bc93 100644 --- a/futures-core/src/task.rs +++ b/futures-core/src/task/mod.rs @@ -1,5 +1,8 @@ //! Task notification. +mod spawn; +pub use self::spawn::{Spawn, LocalSpawn, SpawnError}; + pub use core::task::{Poll, Waker, LocalWaker, UnsafeWake}; if_std! { pub use std::task::{Wake, local_waker, local_waker_from_nonlocal}; diff --git a/futures-core/src/task/spawn.rs b/futures-core/src/task/spawn.rs new file mode 100644 index 0000000000..47f4e195ba --- /dev/null +++ b/futures-core/src/task/spawn.rs @@ -0,0 +1,79 @@ +use crate::future::{FutureObj, LocalFutureObj}; +use core::fmt; + +/// The `Spawn` trait allows for pushing futures onto an executor that will +/// run them to completion. +pub trait Spawn { + /// Spawns a future that will be run to completion. + /// + /// # Errors + /// + /// The executor may be unable to spawn tasks. Spawn errors should + /// represent relatively rare scenarios, such as the executor + /// having been shut down so that it is no longer able to accept + /// tasks. + fn spawn_obj(&mut self, future: FutureObj<'static, ()>) + -> Result<(), SpawnError>; + + /// Determines whether the executor is able to spawn new tasks. + /// + /// This method will return `Ok` when the executor is *likely* + /// (but not guaranteed) to accept a subsequent spawn attempt. + /// Likewise, an `Err` return means that `spawn` is likely, but + /// not guaranteed, to yield an error. + #[inline] + fn status(&self) -> Result<(), SpawnError> { + Ok(()) + } +} + +/// The `LocalSpawn` is similar to `[Spawn]`, but allows spawning futures +/// that don't implement `Send`. +pub trait LocalSpawn { + /// Spawns a future that will be run to completion. + /// + /// # Errors + /// + /// The executor may be unable to spawn tasks. Spawn errors should + /// represent relatively rare scenarios, such as the executor + /// having been shut down so that it is no longer able to accept + /// tasks. + fn spawn_local_obj(&mut self, future: LocalFutureObj<'static, ()>) + -> Result<(), SpawnError>; + + /// Determines whether the executor is able to spawn new tasks. + /// + /// This method will return `Ok` when the executor is *likely* + /// (but not guaranteed) to accept a subsequent spawn attempt. + /// Likewise, an `Err` return means that `spawn` is likely, but + /// not guaranteed, to yield an error. + #[inline] + fn status_local(&self) -> Result<(), SpawnError> { + Ok(()) + } +} + +/// An error that occurred during spawning. +pub struct SpawnError { + _hidden: (), +} + +impl fmt::Debug for SpawnError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("SpanError") + .field(&"shutdown") + .finish() + } +} + +impl SpawnError { + /// Spawning failed because the executor has been shut down. + pub fn shutdown() -> Self { + Self { _hidden: () } + } + + /// Check whether spawning failed to the executor being shut down. + pub fn is_shutdown(&self) -> bool { + true + } +} diff --git a/futures-executor/src/lib.rs b/futures-executor/src/lib.rs index 63f4535d86..fe7e0a3e82 100644 --- a/futures-executor/src/lib.rs +++ b/futures-executor/src/lib.rs @@ -18,7 +18,7 @@ macro_rules! if_std { if_std! { mod local_pool; - pub use crate::local_pool::{block_on, block_on_stream, BlockingStream, LocalPool, LocalSpawn}; + pub use crate::local_pool::{block_on, block_on_stream, BlockingStream, LocalPool, LocalSpawner}; mod unpark_mutex; mod thread_pool; diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index 02f831cd5d..b923483610 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -2,8 +2,8 @@ use crate::{enter, ThreadPool}; use futures_core::future::{Future, FutureObj, LocalFutureObj}; use futures_core::stream::{Stream}; use futures_core::task::{ - self, Context, Poll, LocalWaker, Wake, - Spawn, SpawnObjError, SpawnLocalObjError, SpawnErrorKind + self, Poll, LocalWaker, Wake, + Spawn, LocalSpawn, SpawnError, }; use futures_util::stream::FuturesUnordered; use futures_util::stream::StreamExt; @@ -27,7 +27,7 @@ use std::thread::{self, Thread}; /// [`Spawn`](futures_core::task::Spawn), use the /// [`spawner()`](LocalPool::spawner) method. Because the executor is /// single-threaded, it supports a special form of task spawning for non-`Send` -/// futures, via [`spawn_local_obj`](LocalSpawn::spawn_local_obj). +/// futures, via [`spawn_local_obj`](LocalSpawner::spawn_local_obj). #[derive(Debug)] pub struct LocalPool { pool: FuturesUnordered>, @@ -37,7 +37,7 @@ pub struct LocalPool { /// A handle to a [`LocalPool`](LocalPool) that implements /// [`Spawn`](futures_core::task::Spawn). #[derive(Clone, Debug)] -pub struct LocalSpawn { +pub struct LocalSpawner { incoming: Weak, } @@ -88,8 +88,8 @@ impl LocalPool { } /// Get a clonable handle to the pool as a [`Spawn`]. - pub fn spawner(&self) -> LocalSpawn { - LocalSpawn { + pub fn spawner(&self) -> LocalSpawner { + LocalSpawner { incoming: Rc::downgrade(&self.incoming) } } @@ -114,8 +114,8 @@ impl LocalPool { /// /// The function will block the calling thread until *all* tasks in the pool /// are complete, including any spawned while running existing tasks. - pub fn run(&mut self, spawn: &mut Sp) where Sp: Spawn + Sized { - run_executor(|local_waker| self.poll_pool(local_waker, spawn)) + pub fn run(&mut self) { + run_executor(|local_waker| self.poll_pool(local_waker)) } /// Runs all the tasks in the pool until the given future completes. @@ -143,37 +143,27 @@ impl LocalPool { /// be inert after the call completes, but can continue with further use of /// `run` or `run_until`. While the function is running, however, all tasks /// in the pool will try to make progress. - pub fn run_until(&mut self, future: F, spawn: &mut Sp) - -> F::Output - where F: Future, Sp: Spawn + Sized - { + pub fn run_until(&mut self, future: F) -> F::Output { pin_mut!(future); run_executor(|local_waker| { { - let mut main_lw = Context::new(local_waker, spawn); - // if our main task is done, so are we - let result = future.as_mut().poll(&mut main_lw); + let result = future.as_mut().poll(local_waker); if let Poll::Ready(output) = result { return Poll::Ready(output); } } - self.poll_pool(local_waker, spawn); + self.poll_pool(local_waker); Poll::Pending }) } // Make maximal progress on the entire pool of spawned task, returning `Ready` // if the pool is empty and `Pending` if no further progress can be made. - fn poll_pool(&mut self, local_waker: &LocalWaker, spawn: &mut Sp) - -> Poll<()> - where Sp: Spawn + Sized - { + fn poll_pool(&mut self, local_waker: &LocalWaker) -> Poll<()> { // state for the FuturesUnordered, which will never be used - let mut pool_lw = Context::new(local_waker, spawn); - loop { // empty the incoming queue of newly-spawned tasks { @@ -183,7 +173,7 @@ impl LocalPool { } } - let ret = self.pool.poll_next_unpin(&mut pool_lw); + let ret = self.pool.poll_next_unpin(local_waker); // we queued up some new tasks; add them and poll again if !self.incoming.borrow().is_empty() { continue; @@ -221,7 +211,7 @@ lazy_static! { /// spawned tasks. pub fn block_on(f: F) -> F::Output { let mut pool = LocalPool::new(); - pool.run_until(f, &mut GLOBAL_POOL.clone()) + pool.run_until(f) } /// Turn a stream into a blocking iterator. @@ -260,43 +250,42 @@ impl BlockingStream { impl Iterator for BlockingStream { type Item = S::Item; fn next(&mut self) -> Option { - LocalPool::new().run_until(self.stream.next(), &mut GLOBAL_POOL.clone()) + LocalPool::new().run_until(self.stream.next()) } } -impl Spawn for LocalSpawn { +impl Spawn for LocalSpawner { fn spawn_obj( &mut self, future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { + ) -> Result<(), SpawnError> { if let Some(incoming) = self.incoming.upgrade() { incoming.borrow_mut().push(future.into()); Ok(()) } else { - Err(SpawnObjError{ future, kind: SpawnErrorKind::shutdown() }) + Err(SpawnError::shutdown()) } } - fn status(&self) -> Result<(), SpawnErrorKind> { + fn status(&self) -> Result<(), SpawnError> { if self.incoming.upgrade().is_some() { Ok(()) } else { - Err(SpawnErrorKind::shutdown()) + Err(SpawnError::shutdown()) } } } -impl LocalSpawn { - /// Spawn a non-`Send` future onto the associated [`LocalPool`](LocalPool). - pub fn spawn_local_obj( +impl LocalSpawn for LocalSpawner { + fn spawn_local_obj( &mut self, future: LocalFutureObj<'static, ()>, - ) -> Result<(), SpawnLocalObjError> { + ) -> Result<(), SpawnError> { if let Some(incoming) = self.incoming.upgrade() { incoming.borrow_mut().push(future); Ok(()) } else { - Err(SpawnLocalObjError{ future, kind: SpawnErrorKind::shutdown() }) + Err(SpawnError::shutdown()) } } } diff --git a/futures-executor/src/thread_pool.rs b/futures-executor/src/thread_pool.rs index 7acfd82c3d..125c26e773 100644 --- a/futures-executor/src/thread_pool.rs +++ b/futures-executor/src/thread_pool.rs @@ -1,7 +1,7 @@ use crate::enter; use crate::unpark_mutex::UnparkMutex; use futures_core::future::{Future, FutureObj}; -use futures_core::task::{self, Poll, Wake, Spawn, SpawnObjError}; +use futures_core::task::{Poll, Wake, Spawn, SpawnError}; use futures_util::future::FutureExt; use futures_util::task::local_waker_ref_from_nonlocal; use num_cpus; @@ -95,7 +95,7 @@ impl ThreadPool { /// Note that the function will return when the provided future completes, /// even if some of the tasks it spawned are still running. pub fn run(&mut self, f: F) -> F::Output { - crate::LocalPool::new().run_until(f, self) + crate::LocalPool::new().run_until(f) } } @@ -103,7 +103,7 @@ impl Spawn for ThreadPool { fn spawn_obj( &mut self, future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { + ) -> Result<(), SpawnError> { let task = Task { future, wake_handle: Arc::new(WakeHandle { @@ -298,10 +298,7 @@ impl Task { wake_handle.mutex.start_poll(); loop { - let res = { - let mut lw = task::Context::new(&local_waker, &mut exec); - future.poll_unpin(&mut lw) - }; + let res = future.poll_unpin(&local_waker); match res { Poll::Pending => {} Poll::Ready(()) => return wake_handle.mutex.complete(), diff --git a/futures-util/src/async_await/mod.rs b/futures-util/src/async_await/mod.rs index 1707107ef9..df98ae10c0 100644 --- a/futures-util/src/async_await/mod.rs +++ b/futures-util/src/async_await/mod.rs @@ -22,10 +22,6 @@ mod join; #[macro_use] mod select; -// Primary export is a macro -#[macro_use] -mod spawn; - #[doc(hidden)] #[inline(always)] pub fn assert_unpin(_: &T) {} diff --git a/futures-util/src/async_await/spawn.rs b/futures-util/src/async_await/spawn.rs deleted file mode 100644 index 27b2b45048..0000000000 --- a/futures-util/src/async_await/spawn.rs +++ /dev/null @@ -1,58 +0,0 @@ -/// Spawns a task onto the context's executor that polls the given future with -/// output `()` to completion. -/// -/// This macro returns a [`Result`] that contains a -/// [`SpawnError`](crate::task::SpawnError) if spawning fails. -/// -/// You can use [`spawn_with_handle!`] if you want to spawn a future -/// with output other than `()` or if you want to be able to await its -/// completion. -/// -/// ``` -/// #![feature(async_await, await_macro, futures_api)] -/// # futures::executor::block_on(async { -/// use futures::spawn; -/// -/// let future = async { /* ... */ }; -/// spawn!(future).unwrap(); -/// # }); -/// ``` -#[macro_export] -macro_rules! spawn { - ($future:expr) => { - await!($crate::future::lazy(|lw| { - $crate::task::SpawnExt::spawn(lw.spawner(), $future) - })) - } -} - -/// Spawns a task onto the context's executor that polls the given future to -/// completion and returns a future that resolves to the spawned future's -/// output. -/// -/// This macro returns a [`Result`] that contains a -/// [`JoinHandle`](crate::task::JoinHandle), or, if spawning fails, a -/// [`SpawnError`](crate::task::SpawnError). -/// [`JoinHandle`](crate::task::JoinHandle) is a future that resolves -/// to the output of the spawned future -/// -/// # Examples -/// -/// ``` -/// #![feature(async_await, await_macro, futures_api)] -/// # futures::executor::block_on(async { -/// use futures::{future, spawn_with_handle}; -/// -/// let future = future::ready(1); -/// let join_handle = spawn_with_handle!(future).unwrap(); -/// assert_eq!(await!(join_handle), 1); -/// # }); -/// ``` -#[macro_export] -macro_rules! spawn_with_handle { - ($future:expr) => { - await!($crate::future::lazy(|lw| { - $crate::task::SpawnExt::spawn_with_handle(lw.spawner(), $future) - })) - } -} diff --git a/futures-util/src/stream/futures_unordered/mod.rs b/futures-util/src/stream/futures_unordered/mod.rs index 933901a225..8330a1a393 100644 --- a/futures-util/src/stream/futures_unordered/mod.rs +++ b/futures-util/src/stream/futures_unordered/mod.rs @@ -1,9 +1,9 @@ //! An unbounded set of futures. use crate::task::AtomicWaker; -use futures_core::future::Future; +use futures_core::future::{Future, FutureObj, LocalFutureObj}; use futures_core::stream::Stream; -use futures_core::task::{LocalWaker, Poll}; +use futures_core::task::{LocalWaker, Poll, Spawn, LocalSpawn, SpawnError}; use std::cell::UnsafeCell; use std::fmt::{self, Debug}; use std::iter::FromIterator; @@ -55,6 +55,24 @@ unsafe impl Send for FuturesUnordered {} unsafe impl Sync for FuturesUnordered {} impl Unpin for FuturesUnordered {} +impl<'a> Spawn for FuturesUnordered> { + fn spawn_obj(&mut self, future_obj: FutureObj<'static, ()>) + -> Result<(), SpawnError> + { + self.push(future_obj); + Ok(()) + } +} + +impl<'a> LocalSpawn for FuturesUnordered> { + fn spawn_local_obj(&mut self, future_obj: LocalFutureObj<'static, ()>) + -> Result<(), SpawnError> + { + self.push(future_obj); + Ok(()) + } +} + // FuturesUnordered is implemented using two linked lists. One which links all // futures managed by a `FuturesUnordered` and one that tracks futures that have // been scheduled for polling. The first linked list is not thread safe and is diff --git a/futures/src/lib.rs b/futures/src/lib.rs index cd02b3e19d..51c9c671ab 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -57,7 +57,7 @@ pub use futures_util::{ #[cfg(feature = "std")] pub use futures_util::{ // Async-await - join, try_join, select, pending, poll, spawn, spawn_with_handle, + join, try_join, select, pending, poll, }; #[cfg(feature = "std")] @@ -128,16 +128,11 @@ pub mod executor { //! //! # Spawning additional tasks //! - //! There are two ways to spawn a task: - //! - //! - Spawn onto a "default" spawner by calling the top-level - //! [`spawn`](crate::executor::spawn) function or [pulling the spawner - //! from the task context](crate::task::Context::spawner). - //! - Spawn onto a specific spawner by calling its - //! [`spawn_obj`](crate::executor::Spawn::spawn_obj) method directly. - //! - //! Every task always has an associated default spawner, which is usually - //! the executor on which the task is running. + //! Tasks can be spawned onto a spawner by calling its + //! [`spawn_obj`](crate::task::Spawn::spawn_obj) method directly. + //! In the case of `!Send` futures, + //! [`spawn_local_obj`](crate::task::LocalSpawn::spawn_local_obj) + //! can be used instead. //! //! # Single-threaded execution //! @@ -158,7 +153,7 @@ pub mod executor { pub use futures_executor::{ BlockingStream, Enter, EnterError, - LocalSpawn, LocalPool, + LocalSpawner, LocalPool, ThreadPool, ThreadPoolBuilder, block_on, block_on_stream, enter, }; @@ -193,14 +188,15 @@ pub mod future { FutureExt, FlattenStream, Flatten, Fuse, Inspect, IntoStream, Join, Join3, Join4, - Join5, Map, Then, WithSpawner, + Join5, Map, Then, }; #[cfg(feature = "std")] pub use futures_util::future::{ abortable, Abortable, AbortHandle, AbortRegistration, Aborted, + Remote, RemoteHandle, // For FutureExt: - CatchUnwind, Shared + CatchUnwind, Shared, // ToDo: JoinAll, SelectAll, SelectOk, join_all, select_all, select_ok }; @@ -255,7 +251,6 @@ pub mod prelude { pub use crate::future::{self, Future, TryFuture, FutureExt, TryFutureExt}; pub use crate::stream::{self, Stream, TryStream, StreamExt, TryStreamExt}; - pub use crate::task::{self, Poll, SpawnExt}; pub use crate::sink::{self, Sink, SinkExt}; #[cfg(feature = "std")] @@ -362,9 +357,8 @@ pub mod task { //! executors or dealing with synchronization issues around task wakeup. pub use futures_core::task::{ - Context, Poll, Spawn, + Poll, Spawn, LocalSpawn, SpawnError, Waker, LocalWaker, UnsafeWake, - SpawnErrorKind, SpawnObjError, SpawnLocalObjError, }; #[cfg(feature = "std")] @@ -372,11 +366,9 @@ pub mod task { Wake, local_waker, local_waker_from_nonlocal }; - pub use futures_util::task::{SpawnExt, SpawnError}; - #[cfg(feature = "std")] pub use futures_util::task::{ - LocalWakerRef, local_waker_ref, local_waker_ref_from_nonlocal, JoinHandle + LocalWakerRef, local_waker_ref, local_waker_ref_from_nonlocal, }; #[cfg_attr( From e00cced26b437f051e9db79533d5364e0f9e5b38 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Fri, 28 Sep 2018 16:43:05 -0700 Subject: [PATCH 08/14] Fix some tests --- futures-channel/tests/oneshot.rs | 2 +- futures-executor/src/local_pool.rs | 6 +-- futures-executor/tests/local_pool.rs | 22 ++++---- futures-test/src/assert.rs | 6 +-- futures-test/src/future/assert_unmoved.rs | 2 +- futures-test/src/future/mod.rs | 2 +- futures-test/src/future/pending_once.rs | 4 +- futures-test/src/task/context.rs | 66 ----------------------- futures-test/src/task/mod.rs | 10 ---- futures-test/src/task/noop_spawner.rs | 4 +- futures-test/src/task/noop_waker.rs | 23 +++----- futures-test/src/task/panic_spawner.rs | 4 +- futures-test/src/task/record_spawner.rs | 14 ++--- futures-test/src/task/wake_counter.rs | 9 ++-- futures-util/src/task/atomic_waker.rs | 2 +- futures/tests/abortable.rs | 5 +- futures/tests/eager_drop.rs | 2 +- futures/tests/fuse.rs | 4 +- futures/tests/futures_ordered.rs | 6 +-- futures/tests/futures_unordered.rs | 4 +- futures/tests/shared.rs | 3 +- futures/tests/split.rs | 2 +- 22 files changed, 53 insertions(+), 149 deletions(-) delete mode 100644 futures-test/src/task/context.rs diff --git a/futures-channel/tests/oneshot.rs b/futures-channel/tests/oneshot.rs index cd336edc88..4b4aecc342 100644 --- a/futures-channel/tests/oneshot.rs +++ b/futures-channel/tests/oneshot.rs @@ -3,7 +3,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 futures::task::{LocalWaker, Poll}; use std::pin::Pin; use std::sync::mpsc; use std::thread; diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index b923483610..10a8f190bc 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -104,12 +104,11 @@ impl LocalPool { /// use futures::executor::LocalPool; /// /// let mut pool = LocalPool::new(); - /// let mut spawn = pool.spawner(); /// /// // ... spawn some initial tasks using `spawn.spawn()` or `spawn.spawn_local()` /// /// // run *all* tasks in the pool to completion, including any newly-spawned ones. - /// pool.run(&mut spawn); + /// pool.run(); /// ``` /// /// The function will block the calling thread until *all* tasks in the pool @@ -130,12 +129,11 @@ impl LocalPool { /// use futures::future::ready; /// /// let mut pool = LocalPool::new(); - /// let mut spawn = pool.spawner(); /// # let my_app = ready(()); /// /// // run tasks in the pool until `my_app` completes, by default spawning /// // further tasks back onto the pool - /// pool.run_until(my_app, &mut spawn); + /// pool.run_until(my_app); /// ``` /// /// The function will block the calling thread *only* until the future `f` diff --git a/futures-executor/tests/local_pool.rs b/futures-executor/tests/local_pool.rs index c85541c20f..f06c782fb1 100644 --- a/futures-executor/tests/local_pool.rs +++ b/futures-executor/tests/local_pool.rs @@ -3,7 +3,7 @@ use futures::channel::oneshot; use futures::executor::LocalPool; use futures::future::{Future, lazy}; -use futures::task::{self, Poll, Spawn}; +use futures::task::{LocalWaker, Poll, Spawn, LocalSpawn}; use std::cell::{Cell, RefCell}; use std::pin::Pin; use std::rc::Rc; @@ -28,12 +28,11 @@ fn run_until_single_future() { { let mut pool = LocalPool::new(); - let mut spawn = pool.spawner(); let fut = lazy(|_| { cnt += 1; () }); - assert_eq!(pool.run_until(fut, &mut spawn), ()); + assert_eq!(pool.run_until(fut), ()); } assert_eq!(cnt, 1); @@ -44,7 +43,7 @@ fn run_until_ignores_spawned() { let mut pool = LocalPool::new(); let mut spawn = pool.spawner(); spawn.spawn_local_obj(Box::pinned(pending()).into()).unwrap(); - assert_eq!(pool.run_until(lazy(|_| ()), &mut spawn), ()); + assert_eq!(pool.run_until(lazy(|_| ())), ()); } #[test] @@ -56,7 +55,7 @@ fn run_until_executes_spawned() { tx.send(()).unwrap(); () })).into()).unwrap(); - pool.run_until(rx, &mut spawn).unwrap(); + pool.run_until(rx).unwrap(); } #[test] @@ -76,7 +75,7 @@ fn run_executes_spawned() { () })).into()).unwrap(); - pool.run(&mut spawn); + pool.run(); assert_eq!(cnt.get(), 1); } @@ -99,7 +98,7 @@ fn run_spawn_many() { })).into()).unwrap(); } - pool.run(&mut spawn); + pool.run(); assert_eq!(cnt.get(), ITER); } @@ -112,10 +111,9 @@ fn nesting_run() { spawn.spawn_obj(Box::pinned(lazy(|_| { let mut pool = LocalPool::new(); - let mut spawn = pool.spawner(); - pool.run(&mut spawn); + pool.run(); })).into()).unwrap(); - pool.run(&mut spawn); + pool.run(); } #[test] @@ -149,7 +147,7 @@ fn tasks_are_scheduled_fairly() { return Poll::Ready(()); } - lw.waker().wake(); + lw.wake(); Poll::Pending } } @@ -167,6 +165,6 @@ fn tasks_are_scheduled_fairly() { idx: 1, }).into()).unwrap(); - pool.run(&mut spawn); + pool.run(); } diff --git a/futures-test/src/assert.rs b/futures-test/src/assert.rs index 0d669b97f3..723318221a 100644 --- a/futures-test/src/assert.rs +++ b/futures-test/src/assert.rs @@ -31,7 +31,7 @@ macro_rules! assert_stream_pending { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); let stream = $crate::std_reexport::pin::Pin::new(stream); - let lw = &mut $crate::task::no_spawn_context(); + let lw = &$crate::task::noop_local_waker_ref(); let poll = $crate::futures_core_reexport::stream::Stream::poll_next( stream, lw, ); @@ -68,7 +68,7 @@ macro_rules! assert_stream_next { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); let stream = $crate::std_reexport::pin::Pin::new(stream); - let lw = &mut $crate::task::no_spawn_context(); + let lw = &$crate::task::noop_local_waker_ref(); match $crate::futures_core_reexport::stream::Stream::poll_next(stream, lw) { $crate::futures_core_reexport::task::Poll::Ready(Some(x)) => { assert_eq!(x, $item); @@ -111,7 +111,7 @@ macro_rules! assert_stream_done { let mut stream = &mut $stream; $crate::assert::assert_is_unpin_stream(stream); let stream = $crate::std_reexport::pin::Pin::new(stream); - let lw = &mut $crate::task::no_spawn_context(); + let lw = &$crate::task::noop_local_waker_ref(); match $crate::futures_core_reexport::stream::Stream::poll_next(stream, lw) { $crate::futures_core_reexport::task::Poll::Ready(Some(_)) => { panic!("assertion failed: expected stream to be done but had more elements"); diff --git a/futures-test/src/future/assert_unmoved.rs b/futures-test/src/future/assert_unmoved.rs index 8f53889e0c..77c4bdb7a4 100644 --- a/futures-test/src/future/assert_unmoved.rs +++ b/futures-test/src/future/assert_unmoved.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use pin_utils::{unsafe_pinned, unsafe_unpinned}; use std::marker::Pinned; use std::pin::Pin; diff --git a/futures-test/src/future/mod.rs b/futures-test/src/future/mod.rs index 399e42b288..f340fdd860 100644 --- a/futures-test/src/future/mod.rs +++ b/futures-test/src/future/mod.rs @@ -43,7 +43,7 @@ pub trait FutureTestExt: Future { /// let future = (async { 5 }).pending_once(); /// pin_mut!(future); /// - /// let lw = &mut task::no_spawn_context(); + /// let lw = &task::noop_local_waker_ref(); /// /// assert_eq!(future.poll_unpin(lw), Poll::Pending); /// assert_eq!(future.poll_unpin(lw), Poll::Ready(5)); diff --git a/futures-test/src/future/pending_once.rs b/futures-test/src/future/pending_once.rs index 05ad5ff747..228c66a6f0 100644 --- a/futures-test/src/future/pending_once.rs +++ b/futures-test/src/future/pending_once.rs @@ -1,5 +1,5 @@ use futures_core::future::Future; -use futures_core::task::{self, Poll}; +use futures_core::task::{LocalWaker, Poll}; use std::pin::Pin; use pin_utils::{unsafe_pinned, unsafe_unpinned}; @@ -39,7 +39,7 @@ impl Future for PendingOnce { self.future().poll(lw) } else { *self.polled_before() = true; - lw.waker().wake(); + lw.wake(); Poll::Pending } } diff --git a/futures-test/src/task/context.rs b/futures-test/src/task/context.rs deleted file mode 100644 index d9d8b6c849..0000000000 --- a/futures-test/src/task/context.rs +++ /dev/null @@ -1,66 +0,0 @@ -use crate::task::{panic_local_waker_ref, panic_spawner_mut}; -use crate::task::{noop_local_waker_ref, noop_spawner_mut}; -use futures_core::task::Context; - -/// Create a new [`task::Context`](futures_core::task::Context) where both -/// the [waker](futures_core::task::Context::waker) and -/// [spawner](futures_core::task::Context::spawner) will panic if used. -/// -/// # Examples -/// -/// ```should_panic -/// #![feature(futures_api)] -/// use futures_test::task; -/// -/// let lw = task::panic_context(); -/// lw.waker().wake(); // Will panic -/// ``` -pub fn panic_context() -> Context<'static> { - Context::new(panic_local_waker_ref(), panic_spawner_mut()) -} - -/// Create a new [`task::Context`](futures_core::task::Context) where the -/// [waker](futures_core::task::Context::waker) will ignore any calls to -/// `wake` while the [spawner](futures_core::task::Context::spawner) will -/// panic if used. -/// -/// # Examples -/// -/// ``` -/// #![feature(async_await, futures_api, pin)] -/// use futures::future::Future; -/// use futures::task::Poll; -/// use futures_test::task::no_spawn_context; -/// use pin_utils::pin_mut; -/// -/// let mut future = async { 5 }; -/// pin_mut!(future); -/// -/// assert_eq!(future.poll(&mut no_spawn_context()), Poll::Ready(5)); -/// ``` -pub fn no_spawn_context() -> Context<'static> { - Context::new(noop_local_waker_ref(), panic_spawner_mut()) -} - -/// Create a new [`task::Context`](futures_core::task::Context) where the -/// [waker](futures_core::task::Context::waker) and -/// [spawner](futures_core::task::Context::spawner) will both ignore any -/// uses. -/// -/// # Examples -/// -/// ``` -/// #![feature(async_await, futures_api, pin)] -/// use futures::future::Future; -/// use futures::task::Poll; -/// use futures_test::task::noop_context; -/// use pin_utils::pin_mut; -/// -/// let mut future = async { 5 }; -/// pin_mut!(future); -/// -/// assert_eq!(future.poll(&mut noop_context()), Poll::Ready(5)); -/// ``` -pub fn noop_context() -> Context<'static> { - Context::new(noop_local_waker_ref(), noop_spawner_mut()) -} diff --git a/futures-test/src/task/mod.rs b/futures-test/src/task/mod.rs index cf06056565..c8604c19de 100644 --- a/futures-test/src/task/mod.rs +++ b/futures-test/src/task/mod.rs @@ -5,13 +5,6 @@ //! [`LocalWaker`](futures_core::task::LocalWaker)s and //! [`Spawn`](futures_core::task::Spawn) implementations. //! -//! Commonly needed [`task::Context`](futures_core::task::Context)s can be -//! created via the functions [`no_spawn_context`], -//! [`noop_context`] and [`panic_context`]. For more advanced use cases, you -//! can create your own task context via -//! [`task::Context::new`](futures_core::task::Context::new) and make use -//! of the various provided test wakers and spawners: -//! //! Test wakers: //! - [`noop_local_waker`] creates a waker that ignores calls to //! [`wake`](futures_core::task::LocalWaker). @@ -31,9 +24,6 @@ //! return waker/spawner references: [`noop_local_waker_ref`], //! [`panic_local_waker_ref`], [`noop_spawner_mut`] and [`panic_spawner_mut`]. -mod context; -pub use self::context::{no_spawn_context, noop_context, panic_context}; - mod noop_spawner; pub use self::noop_spawner::{noop_spawner_mut, NoopSpawner}; diff --git a/futures-test/src/task/noop_spawner.rs b/futures-test/src/task/noop_spawner.rs index 3794ffe77c..7e837e746b 100644 --- a/futures-test/src/task/noop_spawner.rs +++ b/futures-test/src/task/noop_spawner.rs @@ -1,5 +1,5 @@ use futures_core::future::FutureObj; -use futures_core::task::{Spawn, SpawnObjError}; +use futures_core::task::{Spawn, SpawnError}; /// An implementation of [`Spawn`](futures_core::task::Spawn) that /// discards spawned futures when used. @@ -33,7 +33,7 @@ impl Spawn for NoopSpawner { fn spawn_obj( &mut self, _future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { + ) -> Result<(), SpawnError> { Ok(()) } } diff --git a/futures-test/src/task/noop_waker.rs b/futures-test/src/task/noop_waker.rs index 70e0a5aec1..3a7dc38248 100644 --- a/futures-test/src/task/noop_waker.rs +++ b/futures-test/src/task/noop_waker.rs @@ -10,12 +10,9 @@ use std::sync::Arc; /// /// ``` /// #![feature(futures_api)] -/// use futures_test::task::{panic_context, noop_local_waker_ref}; -/// -/// let mut lw = panic_context(); -/// let lw = &mut lw.with_waker(noop_local_waker_ref()); -/// -/// lw.waker().wake(); +/// use futures_test::task::noop_local_waker_ref; +/// let lw = noop_local_waker_ref(); +/// lw.wake(); /// ``` #[derive(Debug)] pub struct NoopWake { @@ -71,16 +68,10 @@ pub fn noop_local_waker() -> LocalWaker { /// # Examples /// /// ``` -/// #![feature(async_await, futures_api)] -/// use futures::task; -/// use futures_test::task::{noop_local_waker_ref, noop_spawner_mut}; -/// -/// let mut lw = task::Context::new( -/// noop_local_waker_ref(), -/// noop_spawner_mut(), -/// ); -/// -/// lw.waker().wake(); +/// #![feature(futures_api)] +/// use futures_test::task::noop_local_waker_ref; +/// let lw = noop_local_waker_ref(); +/// lw.wake(); /// ``` pub fn noop_local_waker_ref() -> &'static LocalWaker { thread_local! { diff --git a/futures-test/src/task/panic_spawner.rs b/futures-test/src/task/panic_spawner.rs index 9ed6ef21ce..ae409c9022 100644 --- a/futures-test/src/task/panic_spawner.rs +++ b/futures-test/src/task/panic_spawner.rs @@ -1,5 +1,5 @@ use futures_core::future::FutureObj; -use futures_core::task::{Spawn, SpawnObjError}; +use futures_core::task::{Spawn, SpawnError}; /// An implementation of [`Spawn`](futures_core::task::Spawn) that panics /// when used. @@ -33,7 +33,7 @@ impl Spawn for PanicSpawner { fn spawn_obj( &mut self, _future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { + ) -> Result<(), SpawnError> { panic!("should not spawn") } } diff --git a/futures-test/src/task/record_spawner.rs b/futures-test/src/task/record_spawner.rs index 58733887f8..5ac9aed0ff 100644 --- a/futures-test/src/task/record_spawner.rs +++ b/futures-test/src/task/record_spawner.rs @@ -1,5 +1,5 @@ use futures_core::future::FutureObj; -use futures_core::task::{Spawn, SpawnObjError}; +use futures_core::task::{Spawn, SpawnError}; /// An implementation of [`Spawn`](futures_core::task::Spawn) that records /// any [`Future`](futures_core::future::Future)s spawned on it. @@ -9,16 +9,10 @@ use futures_core::task::{Spawn, SpawnObjError}; /// ``` /// #![feature(async_await, futures_api)] /// use futures::task::SpawnExt; -/// use futures_test::task::{panic_context, RecordSpawner}; +/// use futures_test::task::RecordSpawner; /// /// let mut recorder = RecordSpawner::new(); -/// -/// { -/// let mut lw = panic_context(); -/// let lw = &mut lw.with_spawner(&mut recorder); -/// lw.spawner().spawn(async { }); -/// } -/// +/// recorder.spawn(async { }); /// assert_eq!(recorder.spawned().len(), 1); /// ``` #[derive(Debug)] @@ -44,7 +38,7 @@ impl Spawn for RecordSpawner { fn spawn_obj( &mut self, future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { + ) -> Result<(), SpawnError> { self.spawned.push(future); Ok(()) } diff --git a/futures-test/src/task/wake_counter.rs b/futures-test/src/task/wake_counter.rs index 24920891af..6afaa9ef5a 100644 --- a/futures-test/src/task/wake_counter.rs +++ b/futures-test/src/task/wake_counter.rs @@ -9,16 +9,15 @@ use std::sync::Arc; /// /// ``` /// #![feature(futures_api)] -/// use futures_test::task::{panic_context, WakeCounter}; +/// use futures_test::task::WakeCounter; /// /// let wake_counter = WakeCounter::new(); -/// let mut lw = panic_context(); -/// let lw = &mut lw.with_waker(wake_counter.local_waker()); +/// let lw = wake_counter.local_waker(); /// /// assert_eq!(wake_counter.count(), 0); /// -/// lw.waker().wake(); -/// lw.waker().wake(); +/// lw.wake(); +/// lw.wake(); /// /// assert_eq!(wake_counter.count(), 2); /// ``` diff --git a/futures-util/src/task/atomic_waker.rs b/futures-util/src/task/atomic_waker.rs index f5defe7c78..88ce2e9177 100644 --- a/futures-util/src/task/atomic_waker.rs +++ b/futures-util/src/task/atomic_waker.rs @@ -187,7 +187,7 @@ impl AtomicWaker { /// fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<()> { /// // Register **before** checking `set` to avoid a race condition /// // that would result in lost notifications. - /// self.waker.register(lw.waker()); + /// self.waker.register(lw); /// /// if self.set.load(SeqCst) { /// Poll::Ready(()) diff --git a/futures/tests/abortable.rs b/futures/tests/abortable.rs index 560cba21f9..8738331fdb 100644 --- a/futures/tests/abortable.rs +++ b/futures/tests/abortable.rs @@ -4,7 +4,7 @@ use futures::channel::oneshot; use futures::executor::block_on; use futures::future::{abortable, Aborted, FutureExt}; use futures::task::Poll; -use futures_test::task::{panic_context, WakeCounter}; +use futures_test::task::WakeCounter; #[test] fn abortable_works() { @@ -21,8 +21,7 @@ fn abortable_awakens() { let (mut abortable_rx, abort_handle) = abortable(a_rx); let wake_counter = WakeCounter::new(); - let mut lw = panic_context(); - let lw = &mut lw.with_waker(wake_counter.local_waker()); + let lw = &wake_counter.local_waker(); assert_eq!(0, wake_counter.count()); assert_eq!(Poll::Pending, abortable_rx.poll_unpin(lw)); assert_eq!(0, wake_counter.count()); diff --git a/futures/tests/eager_drop.rs b/futures/tests/eager_drop.rs index c7dd50b2af..13e7cb2e50 100644 --- a/futures/tests/eager_drop.rs +++ b/futures/tests/eager_drop.rs @@ -2,7 +2,7 @@ use futures::channel::oneshot; use futures::future::{self, Future, FutureExt, TryFutureExt}; -use futures::task::{self, Poll}; +use futures::task::{LocalWaker, Poll}; use futures_test::future::FutureTestExt; use pin_utils::unsafe_pinned; use std::pin::Pin; diff --git a/futures/tests/fuse.rs b/futures/tests/fuse.rs index 15b3eccea7..ceacdd877c 100644 --- a/futures/tests/fuse.rs +++ b/futures/tests/fuse.rs @@ -1,12 +1,12 @@ #![feature(pin, arbitrary_self_types, futures_api)] use futures::future::{self, FutureExt}; -use futures_test::task::panic_context; +use futures_test::task::panic_local_waker; #[test] fn fuse() { let mut future = future::ready::(2).fuse(); - let lw = &mut panic_context(); + let lw = &mut panic_local_waker(); assert!(future.poll_unpin(lw).is_ready()); assert!(future.poll_unpin(lw).is_pending()); } diff --git a/futures/tests/futures_ordered.rs b/futures/tests/futures_ordered.rs index a872a8a5ed..e5e34d80b3 100644 --- a/futures/tests/futures_ordered.rs +++ b/futures/tests/futures_ordered.rs @@ -4,7 +4,7 @@ use futures::channel::oneshot; use futures::executor::{block_on, block_on_stream}; use futures::future::{self, FutureExt, FutureObj}; use futures::stream::{StreamExt, futures_ordered, FuturesOrdered}; -use futures_test::task::no_spawn_context; +use futures_test::task::noop_local_waker_ref; #[test] fn works_1() { @@ -15,7 +15,7 @@ fn works_1() { let mut stream = futures_ordered(vec![a_rx, b_rx, c_rx]); b_tx.send(99).unwrap(); - assert!(stream.poll_next_unpin(&mut no_spawn_context()).is_pending()); + assert!(stream.poll_next_unpin(&noop_local_waker_ref()).is_pending()); a_tx.send(33).unwrap(); c_tx.send(33).unwrap(); @@ -38,7 +38,7 @@ fn works_2() { FutureObj::new(Box::new(b_rx.join(c_rx).map(|(a, b)| Ok(a? + b?)))), ]); - let lw = &mut no_spawn_context(); + let lw = &noop_local_waker_ref(); a_tx.send(33).unwrap(); b_tx.send(33).unwrap(); assert!(stream.poll_next_unpin(lw).is_ready()); diff --git a/futures/tests/futures_unordered.rs b/futures/tests/futures_unordered.rs index 34765069c0..cad6f34e94 100644 --- a/futures/tests/futures_unordered.rs +++ b/futures/tests/futures_unordered.rs @@ -7,7 +7,7 @@ use futures::stream::{StreamExt, futures_unordered, FuturesUnordered}; use futures::task::Poll; use futures_test::{assert_stream_done, assert_stream_next}; use futures_test::future::FutureTestExt; -use futures_test::task::no_spawn_context; +use futures_test::task::noop_local_waker_ref; use std::boxed::Box; #[test] @@ -42,7 +42,7 @@ fn works_2() { a_tx.send(9).unwrap(); b_tx.send(10).unwrap(); - let lw = &mut no_spawn_context(); + let lw = &noop_local_waker_ref(); assert_eq!(stream.poll_next_unpin(lw), Poll::Ready(Some(Ok(9)))); c_tx.send(20).unwrap(); assert_eq!(stream.poll_next_unpin(lw), Poll::Ready(Some(Ok(30)))); diff --git a/futures/tests/shared.rs b/futures/tests/shared.rs index 114eead0ab..0fa8dfcd44 100644 --- a/futures/tests/shared.rs +++ b/futures/tests/shared.rs @@ -3,6 +3,7 @@ use futures::channel::oneshot; use futures::executor::{block_on, LocalPool}; use futures::future::{self, FutureExt, LocalFutureObj}; +use futures::task::LocalSpawn; use std::cell::RefCell; use std::rc::Rc; use std::thread; @@ -109,7 +110,7 @@ fn peek() { // Once the Shared has been polled, the value is peekable on the clone. spawn.spawn_local_obj(LocalFutureObj::new(Box::new(f1.map(|_| ())))).unwrap(); - local_pool.run(spawn); + local_pool.run(); for _ in 0..2 { assert_eq!(f2.peek().unwrap(), Ok(42)); } diff --git a/futures/tests/split.rs b/futures/tests/split.rs index ad9365c311..bcbf492194 100644 --- a/futures/tests/split.rs +++ b/futures/tests/split.rs @@ -3,7 +3,7 @@ use futures::executor::block_on; use futures::sink::{Sink, SinkExt}; use futures::stream::{self, Stream, StreamExt}; -use futures::task::{self, Poll}; +use futures::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; use std::pin::Pin; From 008c7a5a65651be89ecd6c628fb25d80aed7b675 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 1 Oct 2018 12:10:33 -0700 Subject: [PATCH 09/14] Fix no-std build --- futures-util/src/future/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/futures-util/src/future/mod.rs b/futures-util/src/future/mod.rs index 018e6a37d2..7badfc8058 100644 --- a/futures-util/src/future/mod.rs +++ b/futures-util/src/future/mod.rs @@ -626,6 +626,7 @@ pub trait FutureExt: Future { /// /// This can be used with spawning executors to easily retrieve the result /// of a future executing on a separate task or thread. + #[cfg(feature = "std")] fn remote_handle(self) -> (Remote, RemoteHandle) where Self: Sized, From b9dcff6851c02d79326e4dbf2db9d1a360512bde Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 1 Oct 2018 12:25:37 -0700 Subject: [PATCH 10/14] Update benchmarks --- futures-channel/Cargo.toml | 1 + futures-channel/benches/sync_mpsc.rs | 170 ++++++++++------------ futures-executor/benches/poll.rs | 68 --------- futures-executor/benches/thread_notify.rs | 12 +- futures-util/benches/futures_unordered.rs | 4 +- 5 files changed, 87 insertions(+), 168 deletions(-) delete mode 100644 futures-executor/benches/poll.rs diff --git a/futures-channel/Cargo.toml b/futures-channel/Cargo.toml index 4051ebf979..5e97175d76 100644 --- a/futures-channel/Cargo.toml +++ b/futures-channel/Cargo.toml @@ -23,4 +23,5 @@ futures-core-preview = { path = "../futures-core", version = "0.3.0-alpha.6", de [dev-dependencies] futures-preview = { path = "../futures", version = "0.3.0-alpha.6", default-features = true } +futures-test-preview = { path = "../futures-test", version = "0.3.0-alpha.6", default-features = true } pin-utils = "0.1.0-alpha.2" diff --git a/futures-channel/benches/sync_mpsc.rs b/futures-channel/benches/sync_mpsc.rs index 77e8ffedef..8e801b1f03 100644 --- a/futures-channel/benches/sync_mpsc.rs +++ b/futures-channel/benches/sync_mpsc.rs @@ -1,91 +1,75 @@ #![feature(test, futures_api, pin, arbitrary_self_types)] -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::Pin; -use std::sync::Arc; -use test::Bencher; - -fn notify_noop() -> LocalWaker { - struct Noop; - - impl Wake for Noop { - fn wake(_: &Arc) {} - } - - task::local_waker_from_nonlocal(Arc::new(Noop)) -} - -fn noop_lw(f: impl FnOnce(&LocalWaker)) { - let pool = LocalPool::new(); - let mut spawn = pool.spawner(); - let waker = notify_noop(); - let lw = &LocalWaker::new(&waker, &mut spawn); - f(lw) -} +extern crate test; +use crate::test::Bencher; + +use { + futures::{ + channel::mpsc::{self, Sender, UnboundedSender}, + ready, + stream::{Stream, StreamExt}, + sink::Sink, + task::{LocalWaker, Poll}, + }, + futures_test::task::noop_local_waker_ref, + std::pin::Pin, +}; /// Single producer, single consumer #[bench] fn unbounded_1_tx(b: &mut Bencher) { - noop_lw(|lw| { - b.iter(|| { - let (tx, mut rx) = mpsc::unbounded(); + let lw = noop_local_waker_ref(); + b.iter(|| { + let (tx, mut rx) = mpsc::unbounded(); - // 1000 iterations to avoid measuring overhead of initialization - // Result should be divided by 1000 - for i in 0..1000 { + // 1000 iterations to avoid measuring overhead of initialization + // Result should be divided by 1000 + for i in 0..1000 { - // Poll, not ready, park - assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); + // Poll, not ready, park + assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); - UnboundedSender::unbounded_send(&tx, i).unwrap(); + UnboundedSender::unbounded_send(&tx, i).unwrap(); - // Now poll ready - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); - } - }) + // Now poll ready + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); + } }) } /// 100 producers, single consumer #[bench] fn unbounded_100_tx(b: &mut Bencher) { - noop_lw(|lw| { - b.iter(|| { - let (tx, mut rx) = mpsc::unbounded(); + let lw = noop_local_waker_ref(); + b.iter(|| { + let (tx, mut rx) = mpsc::unbounded(); - let tx: Vec<_> = (0..100).map(|_| tx.clone()).collect(); + let tx: Vec<_> = (0..100).map(|_| tx.clone()).collect(); - // 1000 send/recv operations total, result should be divided by 1000 - for _ in 0..10 { - for i in 0..tx.len() { - assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); + // 1000 send/recv operations total, result should be divided by 1000 + for _ in 0..10 { + for i in 0..tx.len() { + assert_eq!(Poll::Pending, rx.poll_next_unpin(lw)); - UnboundedSender::unbounded_send(&tx[i], i).unwrap(); + UnboundedSender::unbounded_send(&tx[i], i).unwrap(); - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); - } + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); } - }) + } }) } #[bench] fn unbounded_uncontended(b: &mut Bencher) { - noop_lw(|lw| { - b.iter(|| { - let (tx, mut rx) = mpsc::unbounded(); - - for i in 0..1000 { - UnboundedSender::unbounded_send(&tx, i).expect("send"); - // No need to create a task, because poll is not going to park. - assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); - } - }) + let lw = noop_local_waker_ref(); + b.iter(|| { + let (tx, mut rx) = mpsc::unbounded(); + + for i in 0..1000 { + UnboundedSender::unbounded_send(&tx, i).expect("send"); + // No need to create a task, because poll is not going to park. + assert_eq!(Poll::Ready(Some(i)), rx.poll_next_unpin(lw)); + } }) } @@ -117,46 +101,44 @@ impl Stream for TestSender { /// Single producers, single consumer #[bench] fn bounded_1_tx(b: &mut Bencher) { - noop_lw(|lw| { - b.iter(|| { - let (tx, mut rx) = mpsc::channel(0); + let lw = noop_local_waker_ref(); + b.iter(|| { + let (tx, mut rx) = mpsc::channel(0); - let mut tx = TestSender { tx, last: 0 }; + let mut tx = TestSender { tx, last: 0 }; - for i in 0..1000 { - assert_eq!(Poll::Ready(Some(i + 1)), tx.poll_next_unpin(lw)); - assert_eq!(Poll::Pending, tx.poll_next_unpin(lw)); - assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); - } - }) + for i in 0..1000 { + assert_eq!(Poll::Ready(Some(i + 1)), tx.poll_next_unpin(lw)); + assert_eq!(Poll::Pending, tx.poll_next_unpin(lw)); + assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); + } }) } /// 100 producers, single consumer #[bench] fn bounded_100_tx(b: &mut Bencher) { - noop_lw(|lw| { - b.iter(|| { - // Each sender can send one item after specified capacity - let (tx, mut rx) = mpsc::channel(0); - - let mut tx: Vec<_> = (0..100).map(|_| { - TestSender { - tx: tx.clone(), - last: 0 - } - }).collect(); - - for i in 0..10 { - for j in 0..tx.len() { - // Send an item - assert_eq!(Poll::Ready(Some(i + 1)), tx[j].poll_next_unpin(lw)); - // Then block - assert_eq!(Poll::Pending, tx[j].poll_next_unpin(lw)); - // Recv the item - assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); - } + let lw = noop_local_waker_ref(); + b.iter(|| { + // Each sender can send one item after specified capacity + let (tx, mut rx) = mpsc::channel(0); + + let mut tx: Vec<_> = (0..100).map(|_| { + TestSender { + tx: tx.clone(), + last: 0 + } + }).collect(); + + for i in 0..10 { + for j in 0..tx.len() { + // Send an item + assert_eq!(Poll::Ready(Some(i + 1)), tx[j].poll_next_unpin(lw)); + // Then block + assert_eq!(Poll::Pending, tx[j].poll_next_unpin(lw)); + // Recv the item + assert_eq!(Poll::Ready(Some(i + 1)), rx.poll_next_unpin(lw)); } - }) + } }) } diff --git a/futures-executor/benches/poll.rs b/futures-executor/benches/poll.rs deleted file mode 100644 index 56171315d7..0000000000 --- a/futures-executor/benches/poll.rs +++ /dev/null @@ -1,68 +0,0 @@ -#![feature(test, pin, arbitrary_self_types, futures_api)] - -use futures::executor::LocalPool; -use futures::future::{Future, FutureExt}; -use futures::task::{self, Poll, Waker, LocalWaker, Wake}; -use std::marker::Unpin; -use std::pin::Pin; -use std::sync::Arc; -use test::Bencher; - -fn notify_noop() -> LocalWaker { - struct Noop; - - impl Wake for Noop { - fn wake(_: &Arc) {} - } - - task::local_waker_from_nonlocal(Arc::new(Noop)) -} - -#[bench] -fn task_init(b: &mut Bencher) { - const NUM: u32 = 100_000; - - struct MyFuture { - num: u32, - task: Option, - }; - impl Unpin for MyFuture {} - - impl Future for MyFuture { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll { - if self.num == NUM { - Poll::Ready(()) - } else { - self.num += 1; - - if let Some(ref t) = self.task { - t.wake(); - return Poll::Pending; - } - - let t = lw.waker().clone(); - t.wake(); - self.task = Some(t); - - Poll::Pending - } - } - } - - let mut fut = MyFuture { - num: 0, - task: None, - }; - - let pool = LocalPool::new(); - let mut spawn = pool.spawner(); - let waker = notify_noop(); - let mut lw = task::Context::new(&waker, &mut spawn); - - b.iter(|| { - fut.num = 0; - while let Poll::Pending = fut.poll_unpin(&mut lw) {} - }); -} diff --git a/futures-executor/benches/thread_notify.rs b/futures-executor/benches/thread_notify.rs index c97bd572e9..da2579a075 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 crate::test::Bencher; + use futures::executor::block_on; use futures::future::Future; -use futures::task::{self, Poll, Waker}; +use futures::task::{Poll, LocalWaker, Waker}; use std::marker::Unpin; use std::pin::Pin; -use test::Bencher; #[bench] fn thread_yield_single_thread_one_wait(b: &mut Bencher) { @@ -23,7 +25,7 @@ fn thread_yield_single_thread_one_wait(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - lw.waker().wake(); + lw.wake(); Poll::Pending } } @@ -51,7 +53,7 @@ fn thread_yield_single_thread_many_wait(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - lw.waker().wake(); + lw.wake(); Poll::Pending } } @@ -88,7 +90,7 @@ fn thread_yield_multi_thread(b: &mut Bencher) { Poll::Ready(()) } else { self.rem -= 1; - self.tx.send(lw.waker().clone()).unwrap(); + self.tx.send(lw.clone().into_waker()).unwrap(); Poll::Pending } } diff --git a/futures-util/benches/futures_unordered.rs b/futures-util/benches/futures_unordered.rs index 18e9fcf1d1..80b87d0aba 100644 --- a/futures-util/benches/futures_unordered.rs +++ b/futures-util/benches/futures_unordered.rs @@ -1,5 +1,8 @@ #![feature(test, futures_api)] +extern crate test; +use crate::test::Bencher; + use futures::channel::oneshot; use futures::executor::block_on; use futures::future; @@ -7,7 +10,6 @@ use futures::stream::{StreamExt, FuturesUnordered}; use futures::task::Poll; use std::collections::VecDeque; use std::thread; -use test::Bencher; #[bench] fn oneshots(b: &mut Bencher) { From 2979ba17c88e482fa94a31918545ffc8914fcc27 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Sat, 29 Sep 2018 09:09:09 -0700 Subject: [PATCH 11/14] Re-add SpawnExt and fix remaining doctests --- futures-channel/src/oneshot.rs | 3 - futures-executor/src/local_pool.rs | 8 ++ futures-test/src/task/mod.rs | 1 - futures-test/src/task/noop_spawner.rs | 21 ++-- futures-test/src/task/panic_spawner.rs | 19 +--- futures-test/src/task/panic_waker.rs | 18 +-- futures-util/src/task/mod.rs | 3 + futures-util/src/task/spawn.rs | 149 +++++++++++++++++++++++++ futures/src/lib.rs | 8 +- 9 files changed, 181 insertions(+), 49 deletions(-) create mode 100644 futures-util/src/task/spawn.rs diff --git a/futures-channel/src/oneshot.rs b/futures-channel/src/oneshot.rs index 2b3cadb909..d233a49a85 100644 --- a/futures-channel/src/oneshot.rs +++ b/futures-channel/src/oneshot.rs @@ -401,9 +401,6 @@ impl Receiver { /// Attempts to receive a message outside of the context of a task. /// - /// Useful when a [`Context`](task::Context) is not available - /// such as within a `Drop` impl. - /// /// Does not schedule a task wakeup or have any other side effects. /// /// A return value of `None` must be considered immediately stale (out of diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index 10a8f190bc..b58d30bb6f 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -286,4 +286,12 @@ impl LocalSpawn for LocalSpawner { Err(SpawnError::shutdown()) } } + + fn status_local(&self) -> Result<(), SpawnError> { + if self.incoming.upgrade().is_some() { + Ok(()) + } else { + Err(SpawnError::shutdown()) + } + } } diff --git a/futures-test/src/task/mod.rs b/futures-test/src/task/mod.rs index c8604c19de..5219d34d95 100644 --- a/futures-test/src/task/mod.rs +++ b/futures-test/src/task/mod.rs @@ -1,7 +1,6 @@ //! Task related testing utilities. //! //! This module provides utilities for creating test -//! [`task::Context`](futures_core::task::Context)s, //! [`LocalWaker`](futures_core::task::LocalWaker)s and //! [`Spawn`](futures_core::task::Spawn) implementations. //! diff --git a/futures-test/src/task/noop_spawner.rs b/futures-test/src/task/noop_spawner.rs index 7e837e746b..8882933a1a 100644 --- a/futures-test/src/task/noop_spawner.rs +++ b/futures-test/src/task/noop_spawner.rs @@ -9,13 +9,10 @@ use futures_core::task::{Spawn, SpawnError}; /// ``` /// #![feature(async_await, futures_api)] /// use futures::task::SpawnExt; -/// use futures_test::task::{panic_context, NoopSpawner}; +/// use futures_test::task::NoopSpawner; /// -/// let mut lw = panic_context(); -/// let mut spawn = NoopSpawner::new(); -/// let lw = &mut lw.with_spawner(&mut spawn); -/// -/// lw.spawner().spawn(async { }); +/// let mut spawner = NoopSpawner::new(); +/// spawner.spawn(async { }); /// ``` #[derive(Debug)] pub struct NoopSpawner { @@ -50,15 +47,11 @@ impl Default for NoopSpawner { /// /// ``` /// #![feature(async_await, futures_api)] -/// use futures::task::{self, SpawnExt}; -/// use futures_test::task::{noop_local_waker_ref, noop_spawner_mut}; -/// -/// let mut lw = task::Context::new( -/// noop_local_waker_ref(), -/// noop_spawner_mut(), -/// ); +/// use futures::task::SpawnExt; +/// use futures_test::task::noop_spawner_mut; /// -/// lw.spawner().spawn(async { }); +/// let spawner = noop_spawner_mut(); +/// spawner.spawn(async { }); /// ``` pub fn noop_spawner_mut() -> &'static mut NoopSpawner { Box::leak(Box::new(NoopSpawner::new())) diff --git a/futures-test/src/task/panic_spawner.rs b/futures-test/src/task/panic_spawner.rs index ae409c9022..3e14431c57 100644 --- a/futures-test/src/task/panic_spawner.rs +++ b/futures-test/src/task/panic_spawner.rs @@ -9,13 +9,10 @@ use futures_core::task::{Spawn, SpawnError}; /// ```should_panic /// #![feature(async_await, futures_api)] /// use futures::task::SpawnExt; -/// use futures_test::task::{noop_context, PanicSpawner}; +/// use futures_test::task::PanicSpawner; /// -/// let mut lw = noop_context(); /// let mut spawn = PanicSpawner::new(); -/// let lw = &mut lw.with_spawner(&mut spawn); -/// -/// lw.spawner().spawn(async { }); // Will panic +/// spawn.spawn(async { }); // Will panic /// ``` #[derive(Debug)] pub struct PanicSpawner { @@ -50,15 +47,11 @@ impl Default for PanicSpawner { /// /// ```should_panic /// #![feature(async_await, futures_api)] -/// use futures::task::{self, SpawnExt}; -/// use futures_test::task::{panic_local_waker_ref, panic_spawner_mut}; -/// -/// let mut lw = task::Context::new( -/// panic_local_waker_ref(), -/// panic_spawner_mut(), -/// ); +/// use futures::task::SpawnExt; +/// use futures_test::task::panic_spawner_mut; /// -/// lw.spawner().spawn(async { }); // Will panic +/// let spawner = panic_spawner_mut(); +/// spawner.spawn(async { }); // Will panic /// ``` pub fn panic_spawner_mut() -> &'static mut PanicSpawner { Box::leak(Box::new(PanicSpawner::new())) diff --git a/futures-test/src/task/panic_waker.rs b/futures-test/src/task/panic_waker.rs index 0e54694f9b..6dcad3cbb1 100644 --- a/futures-test/src/task/panic_waker.rs +++ b/futures-test/src/task/panic_waker.rs @@ -10,12 +10,10 @@ use std::sync::Arc; /// /// ```should_panic /// #![feature(futures_api)] -/// use futures_test::task::{noop_context, panic_local_waker_ref}; +/// use futures_test::task::panic_local_waker_ref; /// -/// let mut lw = noop_context(); -/// let lw = &mut lw.with_waker(panic_local_waker_ref()); -/// -/// lw.waker().wake(); // Will panic +/// let lw = panic_local_waker_ref(); +/// lw.wake(); // Will panic /// ``` #[derive(Debug)] pub struct PanicWake { @@ -77,14 +75,10 @@ pub fn panic_local_waker() -> LocalWaker { /// ```should_panic /// #![feature(async_await, futures_api)] /// use futures::task; -/// use futures_test::task::{panic_local_waker_ref, panic_spawner_mut}; -/// -/// let mut lw = task::Context::new( -/// panic_local_waker_ref(), -/// panic_spawner_mut(), -/// ); +/// use futures_test::task::panic_local_waker_ref; /// -/// lw.waker().wake(); // Will panic +/// let lw = panic_local_waker_ref(); +/// lw.wake(); // Will panic /// ``` pub fn panic_local_waker_ref() -> &'static LocalWaker { thread_local! { diff --git a/futures-util/src/task/mod.rs b/futures-util/src/task/mod.rs index 6bf692ab92..3744296770 100644 --- a/futures-util/src/task/mod.rs +++ b/futures-util/src/task/mod.rs @@ -1,5 +1,8 @@ //! Task notification +mod spawn; +pub use self::spawn::{SpawnExt, LocalSpawnExt}; + if_std! { mod local_waker_ref; pub use self::local_waker_ref::{local_waker_ref, local_waker_ref_from_nonlocal, LocalWakerRef}; diff --git a/futures-util/src/task/spawn.rs b/futures-util/src/task/spawn.rs new file mode 100644 index 0000000000..ec549ed1c3 --- /dev/null +++ b/futures-util/src/task/spawn.rs @@ -0,0 +1,149 @@ +use futures_core::task::{LocalSpawn, Spawn}; + +if_std! { + use crate::future::{FutureExt, RemoteHandle}; + use futures_core::future::{Future, FutureObj, LocalFutureObj}; + use futures_core::task::SpawnError; +} + +impl SpawnExt for Sp where Sp: Spawn {} +impl LocalSpawnExt for Sp where Sp: LocalSpawn {} + +/// Extension trait for `Spawn`. +pub trait SpawnExt: Spawn { + /// Spawns a task that polls the given future with output `()` to + /// completion. + /// + /// This method returns a [`Result`] that contains a [`SpawnError`] if + /// spawning fails. + /// + /// You can use [`spawn_with_handle`](SpawnExt::spawn_with_handle) if + /// you want to spawn a future with output other than `()` or if you want + /// to be able to await its completion. + /// + /// Note this method will eventually be replaced with the upcoming + /// `Spawn::spawn` method which will take a `dyn Future` as input. + /// Technical limitations prevent `Spawn::spawn` from being implemented + /// today. Feel free to use this method in the meantime. + /// + /// ``` + /// #![feature(async_await, await_macro, futures_api)] + /// use futures::executor::ThreadPool; + /// use futures::task::SpawnExt; + /// + /// let mut executor = ThreadPool::new().unwrap(); + /// + /// let future = async { /* ... */ }; + /// executor.spawn(future).unwrap(); + /// ``` + #[cfg(feature = "std")] + fn spawn(&mut self, future: Fut) -> Result<(), SpawnError> + where + Fut: Future + Send + 'static, + { + self.spawn_obj(FutureObj::new(Box::new(future))) + } + + /// Spawns a task that polls the given future to completion and returns a + /// future that resolves to the spawned future's output. + /// + /// This method returns a [`Result`] that contains a [`JoinHandle`], or, if + /// spawning fails, a [`SpawnError`]. [`JoinHandle`] is a future that + /// resolves to the output of the spawned future. + /// + /// ``` + /// #![feature(async_await, await_macro, futures_api)] + /// use futures::executor::ThreadPool; + /// use futures::future; + /// use futures::task::SpawnExt; + /// + /// let mut executor = ThreadPool::new().unwrap(); + /// + /// let future = future::ready(1); + /// let join_handle_fut = executor.spawn_with_handle(future).unwrap(); + /// assert_eq!(executor.run(join_handle_fut), 1); + /// ``` + #[cfg(feature = "std")] + fn spawn_with_handle( + &mut self, + future: Fut + ) -> Result, SpawnError> + where + Fut: Future + Send + 'static, + Fut::Output: Send, + { + let (future, handle) = future.remote_handle(); + self.spawn(future)?; + Ok(handle) + } +} + +/// Extension trait for `LocalSpawn`. +pub trait LocalSpawnExt: LocalSpawn { + /// Spawns a task that polls the given future with output `()` to + /// completion. + /// + /// This method returns a [`Result`] that contains a [`SpawnError`] if + /// spawning fails. + /// + /// You can use [`spawn_with_handle`](SpawnExt::spawn_with_handle) if + /// you want to spawn a future with output other than `()` or if you want + /// to be able to await its completion. + /// + /// Note this method will eventually be replaced with the upcoming + /// `Spawn::spawn` method which will take a `dyn Future` as input. + /// Technical limitations prevent `Spawn::spawn` from being implemented + /// today. Feel free to use this method in the meantime. + /// + /// ``` + /// #![feature(async_await, await_macro, futures_api)] + /// use futures::executor::LocalPool; + /// use futures::task::LocalSpawnExt; + /// + /// let executor = LocalPool::new(); + /// let mut spawner = executor.spawner(); + /// + /// let future = async { /* ... */ }; + /// spawner.spawn_local(future).unwrap(); + /// ``` + #[cfg(feature = "std")] + fn spawn_local(&mut self, future: Fut) -> Result<(), SpawnError> + where + Fut: Future + 'static, + { + self.spawn_local_obj(LocalFutureObj::new(Box::new(future))) + } + + /// Spawns a task that polls the given future to completion and returns a + /// future that resolves to the spawned future's output. + /// + /// This method returns a [`Result`] that contains a [`JoinHandle`], or, if + /// spawning fails, a [`SpawnError`]. [`JoinHandle`] is a future that + /// resolves to the output of the spawned future. + /// + /// ``` + /// #![feature(async_await, await_macro, futures_api)] + /// use futures::executor::LocalPool; + /// use futures::future; + /// use futures::task::LocalSpawnExt; + /// + /// let mut executor = LocalPool::new(); + /// let mut spawner = executor.spawner(); + /// + /// let future = future::ready(1); + /// let join_handle_fut = spawner.spawn_local_with_handle(future).unwrap(); + /// assert_eq!(executor.run_until(join_handle_fut), 1); + /// ``` + #[cfg(feature = "std")] + fn spawn_local_with_handle( + &mut self, + future: Fut + ) -> Result, SpawnError> + where + Fut: Future + 'static, + { + let (future, handle) = future.remote_handle(); + self.spawn_local(future)?; + Ok(handle) + } +} diff --git a/futures/src/lib.rs b/futures/src/lib.rs index 51c9c671ab..32175a9994 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -345,14 +345,9 @@ pub mod task { //! //! This module contains: //! - //! - [`Context`](crate::task::Context), which provides contextual data - //! present for every task, including a handle for waking up the task. + //! - [`Spawn`](crate::task::Spawn), a trait for spawning new tasks. //! - [`Waker`](crate::task::Waker), a handle for waking up a task. //! - //! Tasks themselves are generally created by spawning a future onto [an - //! executor](crate::executor). However, you can manually construct a task - //! by creating your own `Context` instance, and polling a future with it. - //! //! The remaining types and traits in the module are used for implementing //! executors or dealing with synchronization issues around task wakeup. @@ -369,6 +364,7 @@ pub mod task { #[cfg(feature = "std")] pub use futures_util::task::{ LocalWakerRef, local_waker_ref, local_waker_ref_from_nonlocal, + SpawnExt, LocalSpawnExt, }; #[cfg_attr( From b6cce840d18340e4a001b1c571175d958c16f9dd Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 1 Oct 2018 12:53:42 -0700 Subject: [PATCH 12/14] Update doc links --- futures-core/src/future/future_obj.rs | 1 + futures-core/src/lib.rs | 1 + futures-util/src/stream/mod.rs | 10 ++++++---- futures-util/src/task/spawn.rs | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/futures-core/src/future/future_obj.rs b/futures-core/src/future/future_obj.rs index cb5fc711a4..90326ac7b0 100644 --- a/futures-core/src/future/future_obj.rs +++ b/futures-core/src/future/future_obj.rs @@ -229,6 +229,7 @@ if_std! { } unsafe fn drop(ptr: *mut ()) { + #[allow(clippy::cast_ptr_alignment)] drop(Box::from_raw(ptr as *mut Pin>)); } } diff --git a/futures-core/src/lib.rs b/futures-core/src/lib.rs index cd58433e87..4e0a067aa8 100644 --- a/futures-core/src/lib.rs +++ b/futures-core/src/lib.rs @@ -1,6 +1,7 @@ //! Core traits and types for asynchronous operations in Rust. #![feature(pin, arbitrary_self_types, futures_api)] +#![feature(tool_lints)] // to allow clippy lints #![no_std] diff --git a/futures-util/src/stream/mod.rs b/futures-util/src/stream/mod.rs index 51cb14589c..53859ab3a0 100644 --- a/futures-util/src/stream/mod.rs +++ b/futures-util/src/stream/mod.rs @@ -138,8 +138,9 @@ pub trait StreamExt: Stream { /// Note that because `next` doesn't take ownership over the stream, /// the [`Stream`] type must be [`Unpin`]. If you want to use `next` with a /// [`!Unpin`](Unpin) stream, you'll first have to pin the stream. This can - /// be done by wrapping the stream in a [`PinBox`](std::boxed::PinBox) or - /// pinning it to the stack using the `pin_mut!` macro. + /// be done by boxing the stream using [`Box::pinned`] or + /// pinning it to the stack using the `pin_mut!` macro from the `pin_utils` + /// crate. /// /// # Examples /// @@ -170,8 +171,9 @@ pub trait StreamExt: Stream { /// Note that because `into_future` moves the stream, the [`Stream`] type /// must be [`Unpin`]. If you want to use `into_future` with a /// [`!Unpin`](Unpin) stream, you'll first have to pin the stream. This can - /// be done by wrapping the stream in a [`PinBox`](std::boxed::PinBox) or - /// pinning it to the stack using the `pin_mut!` macro. + /// be done by boxing the stream using [`Box::pinned`] or + /// pinning it to the stack using the `pin_mut!` macro from the `pin_utils` + /// crate. /// /// # Examples /// diff --git a/futures-util/src/task/spawn.rs b/futures-util/src/task/spawn.rs index ec549ed1c3..509556e219 100644 --- a/futures-util/src/task/spawn.rs +++ b/futures-util/src/task/spawn.rs @@ -47,8 +47,8 @@ pub trait SpawnExt: Spawn { /// Spawns a task that polls the given future to completion and returns a /// future that resolves to the spawned future's output. /// - /// This method returns a [`Result`] that contains a [`JoinHandle`], or, if - /// spawning fails, a [`SpawnError`]. [`JoinHandle`] is a future that + /// This method returns a [`Result`] that contains a [`RemoteHandle`], or, if + /// spawning fails, a [`SpawnError`]. [`RemoteHandle`] is a future that /// resolves to the output of the spawned future. /// /// ``` @@ -117,8 +117,8 @@ pub trait LocalSpawnExt: LocalSpawn { /// Spawns a task that polls the given future to completion and returns a /// future that resolves to the spawned future's output. /// - /// This method returns a [`Result`] that contains a [`JoinHandle`], or, if - /// spawning fails, a [`SpawnError`]. [`JoinHandle`] is a future that + /// This method returns a [`Result`] that contains a [`RemoteHandle`], or, if + /// spawning fails, a [`SpawnError`]. [`RemoteHandle`] is a future that /// resolves to the output of the spawned future. /// /// ``` From ce3aba735c5ba53529ed454771c69d8a65d062b1 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 1 Oct 2018 15:39:32 -0700 Subject: [PATCH 13/14] Update compat --- futures-util/Cargo.toml | 3 +- futures-util/src/compat/compat.rs | 9 +++--- futures-util/src/compat/compat01to03.rs | 21 ++++++++------ futures-util/src/compat/compat03to01.rs | 20 +++++-------- futures-util/src/compat/executor.rs | 28 ++++++------------- futures-util/src/compat/future01ext.rs | 4 +-- futures-util/src/compat/mod.rs | 2 +- futures-util/src/compat/stream01ext.rs | 4 +-- futures-util/src/compat/tokio.rs | 10 +++---- futures-util/src/future/with_spawner.rs | 37 ------------------------- futures-util/src/sink/mod.rs | 8 ++---- futures-util/src/try_future/mod.rs | 6 ++-- futures-util/src/try_stream/mod.rs | 11 ++------ 13 files changed, 51 insertions(+), 112 deletions(-) delete mode 100644 futures-util/src/future/with_spawner.rs diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index 5a065e44d1..cb38f6d7fe 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -18,7 +18,7 @@ name = "futures_util" std = ["futures-core-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "either/use_std", "slab"] default = ["std", "futures-core-preview/either", "futures-sink-preview/either"] compat = ["std", "futures"] -tokio-compat = ["compat"] +tokio-compat = ["compat", "tokio-executor"] bench = [] nightly = [] @@ -30,6 +30,7 @@ futures-sink-preview = { path = "../futures-sink", version = "0.3.0-alpha.6", de either = { version = "1.4", default-features = false } slab = { version = "0.4", optional = true } futures = { version = "0.1", optional = true } +tokio-executor = { version = "0.1.2", optional = true } pin-utils = "0.1.0-alpha.2" [dev-dependencies] diff --git a/futures-util/src/compat/compat.rs b/futures-util/src/compat/compat.rs index 3bfc75931a..396909cdd9 100644 --- a/futures-util/src/compat/compat.rs +++ b/futures-util/src/compat/compat.rs @@ -6,19 +6,18 @@ /// [`Sink`](futures::sink::Sink) and vice versa. #[derive(Debug)] #[must_use = "futures do nothing unless polled"] -pub struct Compat { +pub struct Compat { pub(crate) inner: T, - pub(crate) spawn: Option, } -impl Compat { +impl Compat { /// Returns the inner item. pub fn into_inner(self) -> T { self.inner } /// Creates a new [`Compat`]. - pub(crate) fn new(inner: T, spawn: Option) -> Compat { - Compat { inner, spawn } + pub(crate) fn new(inner: T) -> Compat { + Compat { inner } } } diff --git a/futures-util/src/compat/compat01to03.rs b/futures-util/src/compat/compat01to03.rs index a5da352341..481508a97a 100644 --- a/futures-util/src/compat/compat01to03.rs +++ b/futures-util/src/compat/compat01to03.rs @@ -5,17 +5,23 @@ 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::mem; +use std::task::{LocalWaker, Waker}; use std::pin::Pin; -impl Future03 for Compat { +// TODO(cramertj) use as_waker from std when it lands +fn local_as_waker(lw: &LocalWaker) -> &Waker { + unsafe { mem::transmute(lw) } +} + +impl Future03 for Compat { type Output = Result; fn poll( self: Pin<&mut Self>, - lw: &mut task03::Context, + lw: &LocalWaker, ) -> task03::Poll { - let notify = &WakerToHandle(lw.waker()); - + let notify = &WakerToHandle(local_as_waker(lw)); executor01::with_notify(notify, 0, move || { match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { Ok(Async01::Ready(t)) => task03::Poll::Ready(Ok(t)), @@ -26,15 +32,14 @@ impl Future03 for Compat { } } -impl Stream03 for Compat { +impl Stream03 for Compat { type Item = Result; fn poll_next( self: Pin<&mut Self>, - lw: &mut task03::Context, + lw: &LocalWaker, ) -> task03::Poll> { - let notify = &WakerToHandle(lw.waker()); - + let notify = &WakerToHandle(local_as_waker(lw)); executor01::with_notify(notify, 0, move || { match unsafe { Pin::get_mut_unchecked(self) }.inner.poll() { Ok(Async01::Ready(Some(t))) => task03::Poll::Ready(Some(Ok(t))), diff --git a/futures-util/src/compat/compat03to01.rs b/futures-util/src/compat/compat03to01.rs index d6fd5d3348..d19fbe2b5f 100644 --- a/futures-util/src/compat/compat03to01.rs +++ b/futures-util/src/compat/compat03to01.rs @@ -10,10 +10,9 @@ use futures_core::{ use futures_sink::Sink as Sink03; use std::{marker::Unpin, pin::PinMut, ptr::NonNull, sync::Arc}; -impl Future01 for Compat +impl Future01 for Compat where Fut: TryFuture03 + Unpin, - Sp: task03::Spawn, { type Item = Fut::Ok; type Error = Fut::Error; @@ -27,10 +26,9 @@ where } } -impl Stream01 for Compat +impl Stream01 for Compat where St: TryStream03 + Unpin, - Sp: task03::Spawn, { type Item = St::Ok; type Error = St::Error; @@ -45,10 +43,9 @@ where } } -impl Sink01 for Compat +impl Sink01 for Compat where T: Sink03 + Unpin, - E: task03::Spawn, { type SinkItem = T::SinkItem; type SinkError = T::SinkError; @@ -116,14 +113,11 @@ impl task03::Wake for CurrentOwned { } } -fn with_context(compat: &mut Compat, f: F) -> R +fn with_context(compat: &mut Compat, f: F) -> R where T: Unpin, - E: task03::Spawn, - F: FnOnce(Pin<&mut T>, &mut task03::Context) -> R, + F: FnOnce(Pin<&mut T>, &task03::LocalWaker) -> R, { - let waker = current_ref_as_waker(); - let spawn = compat.spawn.as_mut().unwrap(); - let mut lw = task03::Context::new(&waker, spawn); - f(Pin::new(&mut compat.inner), &mut lw) + let lw = current_ref_as_waker(); + f(Pin::new(&mut compat.inner), &lw) } diff --git a/futures-util/src/compat/executor.rs b/futures-util/src/compat/executor.rs index 95cfc91820..61a568e8b4 100644 --- a/futures-util/src/compat/executor.rs +++ b/futures-util/src/compat/executor.rs @@ -2,13 +2,12 @@ use super::Compat; use crate::{TryFutureExt, FutureExt, future::UnitError}; use futures::future::Executor as Executor01; -use futures_core::task::Spawn as Spawn03; -use futures_core::task as task03; +use futures_core::task::{Spawn as Spawn03, SpawnError as SpawnError03}; use futures_core::future::FutureObj; /// A future that can run on a futures 0.1 /// [`Executor`](futures::future::Executor). -pub type Executor01Future = Compat>, Box>; +pub type Executor01Future = Compat>>; /// Extension trait for futures 0.1 [`Executor`](futures::future::Executor). pub trait Executor01CompatExt: Executor01 + @@ -26,7 +25,6 @@ pub trait Executor01CompatExt: Executor01 + /// use tokio_threadpool::ThreadPool; /// /// let pool01 = ThreadPool::new(); - /// let spawner03 = pool01.sender().clone().compat(); /// # let (tx, rx) = futures::channel::oneshot::channel(); /// /// let future03 = async { @@ -37,7 +35,7 @@ pub trait Executor01CompatExt: Executor01 + /// }).unwrap(); /// }; /// - /// let future01 = future03.unit_error().boxed().compat(spawner03); + /// let future01 = future03.unit_error().boxed().compat(); /// /// pool01.spawn(future01); /// pool01.shutdown_on_idle().wait().unwrap(); @@ -71,21 +69,11 @@ where Ex: Executor01, fn spawn_obj( &mut self, future: FutureObj<'static, ()>, - ) -> Result<(), task03::SpawnObjError> { - let exec: Box = Box::new(self.clone()); - let future = future.unit_error().compat(exec); + ) -> Result<(), SpawnError03> { + let future = future.unit_error().compat(); - match self.executor01.execute(future) { - Ok(()) => Ok(()), - Err(err) => { - use futures_core::task::{SpawnObjError, SpawnErrorKind}; - - let fut = err.into_future().into_inner().unwrap_or_else(|_| ()); - Err(SpawnObjError { - kind: SpawnErrorKind::shutdown(), - future: Box::new(fut).into(), - }) - } - } + self.executor01.execute(future).map_err(|_| + SpawnError03::shutdown() + ) } } diff --git a/futures-util/src/compat/future01ext.rs b/futures-util/src/compat/future01ext.rs index 605f6a546c..1286f10cc6 100644 --- a/futures-util/src/compat/future01ext.rs +++ b/futures-util/src/compat/future01ext.rs @@ -9,7 +9,7 @@ pub trait Future01CompatExt: Future01 { /// [`Future`](futures::future::Future) /// into a futures 0.3 /// [`Future>`](futures_core::future::Future). - fn compat(self) -> Compat where Self: Sized { - Compat::new(self, None) + fn compat(self) -> Compat where Self: Sized { + Compat::new(self) } } diff --git a/futures-util/src/compat/mod.rs b/futures-util/src/compat/mod.rs index 702de3aa50..52db15bb91 100644 --- a/futures-util/src/compat/mod.rs +++ b/futures-util/src/compat/mod.rs @@ -5,7 +5,7 @@ mod executor; pub use self::executor::{Executor01CompatExt, Executor01Future, Executor01As03}; -#[allow(module_inception)] mod compat; +mod compat; pub use self::compat::Compat; mod compat01to03; diff --git a/futures-util/src/compat/stream01ext.rs b/futures-util/src/compat/stream01ext.rs index 097894cbfe..a09a43395c 100644 --- a/futures-util/src/compat/stream01ext.rs +++ b/futures-util/src/compat/stream01ext.rs @@ -9,7 +9,7 @@ pub trait Stream01CompatExt: Stream01 { /// [`Stream`](futures::stream::Stream) /// into a futures 0.3 /// [`Stream>`](futures_core::stream::Stream). - fn compat(self) -> Compat where Self: Sized { - Compat::new(self, None) + fn compat(self) -> Compat where Self: Sized { + Compat::new(self) } } diff --git a/futures-util/src/compat/tokio.rs b/futures-util/src/compat/tokio.rs index b7e4ccc0ed..13ae2dc732 100644 --- a/futures-util/src/compat/tokio.rs +++ b/futures-util/src/compat/tokio.rs @@ -1,6 +1,6 @@ use crate::{future::FutureExt, try_future::TryFutureExt}; use futures_core::future::FutureObj; -use futures_core::task::{Spawn, SpawnErrorKind, SpawnObjError}; +use futures_core::task::{Spawn, SpawnError}; use tokio_executor::{DefaultExecutor, Executor as TokioExecutor}; /// A spawner that delegates to `tokio`'s @@ -43,8 +43,8 @@ impl Spawn for TokioDefaultSpawner { fn spawn_obj( &mut self, future: FutureObj<'static, ()>, - ) -> Result<(), SpawnObjError> { - let fut = Box::new(future.unit_error().compat(*self)); + ) -> Result<(), SpawnError> { + let fut = Box::new(future.unit_error().compat()); DefaultExecutor::current().spawn(fut).map_err(|err| { panic!( "tokio failed to spawn and doesn't return the future: {:?}", @@ -53,10 +53,10 @@ impl Spawn for TokioDefaultSpawner { }) } - fn status(&self) -> Result<(), SpawnErrorKind> { + fn status(&self) -> Result<(), SpawnError> { DefaultExecutor::current().status().map_err(|err| { if err.is_shutdown() { - SpawnErrorKind::shutdown() + SpawnError::shutdown() } else { panic!( "tokio executor failed for non-shutdown reason: {:?}", diff --git a/futures-util/src/future/with_spawner.rs b/futures-util/src/future/with_spawner.rs deleted file mode 100644 index 57cc477de3..0000000000 --- a/futures-util/src/future/with_spawner.rs +++ /dev/null @@ -1,37 +0,0 @@ -use core::marker::Unpin; -use core::pin::Pin; -use futures_core::future::Future; -use futures_core::task::{LocalWaker, Poll, Spawn}; - -/// Future for the `with_spawner` combinator, assigning a [`Spawn`] -/// to be used when spawning other futures. -/// -/// This is created by the `Future::with_spawner` method. -#[derive(Debug)] -#[must_use = "futures do nothing unless polled"] -pub struct WithSpawner where Fut: Future, Sp: Spawn { - spawner: Sp, - future: Fut -} - -impl WithSpawner { - pub(super) fn new(future: Fut, spawner: Sp) -> WithSpawner { - WithSpawner { spawner, future } - } -} - -impl Unpin for WithSpawner {} - -impl Future for WithSpawner - where Fut: Future, - Sp: Spawn, -{ - type Output = Fut::Output; - - fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> 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 lw.with_spawner(spawner)) - } -} diff --git a/futures-util/src/sink/mod.rs b/futures-util/src/sink/mod.rs index 4cd1cf6567..5de042bf19 100644 --- a/futures-util/src/sink/mod.rs +++ b/futures-util/src/sink/mod.rs @@ -12,9 +12,6 @@ use futures_sink::Sink; #[cfg(feature = "compat")] use crate::compat::Compat; -#[cfg(feature = "compat")] -use futures_core::task::Spawn; - mod close; pub use self::close::Close; @@ -256,10 +253,9 @@ pub trait SinkExt: Sink { /// Wraps a [`Sink`] into a sink compatible with libraries using /// futures 0.1 `Sink`. Requires the `compat` feature to be enabled. #[cfg(feature = "compat")] - fn compat(self, spawn: Sp) -> Compat + fn compat(self) -> Compat where Self: Sized + Unpin, - Sp: Spawn, { - Compat::new(self, Some(spawn)) + Compat::new(self) } } diff --git a/futures-util/src/try_future/mod.rs b/futures-util/src/try_future/mod.rs index d536c5523a..5b544b4a4f 100644 --- a/futures-util/src/try_future/mod.rs +++ b/futures-util/src/try_future/mod.rs @@ -8,7 +8,6 @@ use futures_sink::Sink; #[cfg(feature = "compat")] use crate::compat::Compat; #[cfg(feature = "compat")] use core::marker::Unpin; -#[cfg(feature = "compat")] use futures_core::task::Spawn; /* TODO mod join; @@ -478,11 +477,10 @@ pub trait TryFutureExt: TryFuture { /// Wraps a [`TryFuture`] into a future compatable with libraries using /// futures 0.1 future definitons. Requires the `compat` feature to enable. #[cfg(feature = "compat")] - fn compat(self, spawn: Sp) -> Compat + fn compat(self) -> Compat where Self: Sized + Unpin, - Sp: Spawn, { - Compat::new(self, Some(spawn)) + Compat::new(self) } /// Wraps a [`TryFuture`] into a type that implements diff --git a/futures-util/src/try_stream/mod.rs b/futures-util/src/try_stream/mod.rs index 596037ac66..0917ae2603 100644 --- a/futures-util/src/try_stream/mod.rs +++ b/futures-util/src/try_stream/mod.rs @@ -10,9 +10,6 @@ use futures_core::stream::TryStream; #[cfg(feature = "compat")] use crate::compat::Compat; -#[cfg(feature = "compat")] -use futures_core::task::Spawn; - mod err_into; pub use self::err_into::ErrInto; @@ -510,7 +507,6 @@ pub trait TryStreamExt: TryStream { /// #![feature(async_await, await_macro, futures_api)] /// use futures::future::{FutureExt, TryFutureExt}; /// use futures::spawn; - /// use futures::compat::TokioDefaultSpawner; /// # let (tx, rx) = futures::channel::oneshot::channel(); /// /// let future03 = async { @@ -524,16 +520,15 @@ pub trait TryStreamExt: TryStream { /// let future01 = future03 /// .unit_error() // Make it a TryFuture /// .boxed() // Make it Unpin - /// .compat(TokioDefaultSpawner); + /// .compat(); /// /// tokio::run(future01); /// # futures::executor::block_on(rx).unwrap(); /// ``` #[cfg(feature = "compat")] - fn compat(self, spawn: Sp) -> Compat + fn compat(self) -> Compat where Self: Sized + Unpin, - Sp: Spawn, { - Compat::new(self, Some(spawn)) + Compat::new(self) } } From b6a2e21362cc8b0cc5be00678016b90a91a151b4 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 1 Oct 2018 15:40:00 -0700 Subject: [PATCH 14/14] Remove pin_utils pin --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b13b085ee..f02526a563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,3 @@ members = [ "futures-util", "futures-test", ] - -[patch.crates-io] -pin-utils = { git = "https://github.com/Kroisse/pin-utils.git", branch = "pin" }