From 12b2567b959ec754e6f58fb76b88a1a38f805771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Thu, 5 Sep 2024 09:54:06 +0200 Subject: [PATCH] chore: use `poll_fn` from std (#6810) --- tests-integration/src/bin/test-mem.rs | 2 +- tests-integration/tests/process_stdio.rs | 2 +- tokio-stream/src/lib.rs | 3 - tokio-stream/src/poll_fn.rs | 35 ----------- tokio-stream/src/stream_map.rs | 3 +- tokio-util/src/util/poll_buf.rs | 4 +- tokio-util/tests/io_inspect.rs | 2 +- tokio-util/tests/mpsc.rs | 2 +- tokio-util/tests/poll_semaphore.rs | 4 +- tokio/src/fs/file.rs | 2 +- tokio/src/fs/read_dir.rs | 2 +- tokio/src/future/mod.rs | 4 -- tokio/src/future/poll_fn.rs | 60 ------------------- tokio/src/io/util/copy_bidirectional.rs | 2 +- tokio/src/io/util/lines.rs | 2 +- tokio/src/io/util/split.rs | 2 +- tokio/src/macros/support.rs | 3 +- tokio/src/net/tcp/split.rs | 4 +- tokio/src/net/tcp/split_owned.rs | 4 +- tokio/src/net/tcp/stream.rs | 4 +- tokio/src/net/unix/stream.rs | 2 +- tokio/src/runtime/coop.rs | 2 +- tokio/src/runtime/io/registration.rs | 2 +- .../runtime/scheduler/current_thread/mod.rs | 3 +- tokio/src/runtime/tests/loom_local.rs | 2 +- tokio/src/runtime/tests/loom_multi_thread.rs | 3 +- .../runtime/tests/loom_multi_thread_alt.rs | 3 +- tokio/src/runtime/tests/task.rs | 2 +- tokio/src/runtime/time/tests/mod.rs | 15 +---- tokio/src/signal/mod.rs | 2 +- tokio/src/sync/mpsc/bounded.rs | 4 +- tokio/src/sync/mpsc/unbounded.rs | 4 +- tokio/src/sync/oneshot.rs | 4 +- tokio/src/sync/tests/loom_atomic_waker.rs | 2 +- tokio/src/sync/tests/loom_mpsc.rs | 2 +- tokio/src/sync/tests/loom_notify.rs | 3 +- tokio/src/sync/tests/loom_oneshot.rs | 2 +- tokio/src/sync/tests/loom_semaphore_batch.rs | 3 +- tokio/src/task/consume_budget.rs | 2 +- tokio/src/task/join_set.rs | 4 +- tokio/src/task/local.rs | 2 +- tokio/src/time/interval.rs | 3 +- tokio/tests/io_async_fd.rs | 12 ++-- tokio/tests/io_take.rs | 2 +- tokio/tests/macros_select.rs | 2 +- tokio/tests/rt_common.rs | 5 +- tokio/tests/rt_threaded.rs | 3 +- tokio/tests/rt_threaded_alt.rs | 3 +- tokio/tests/tcp_accept.rs | 3 +- tokio/tests/tcp_stream.rs | 3 +- tokio/tests/udp.rs | 2 +- tokio/tests/uds_datagram.rs | 2 +- 52 files changed, 67 insertions(+), 187 deletions(-) delete mode 100644 tokio-stream/src/poll_fn.rs delete mode 100644 tokio/src/future/poll_fn.rs diff --git a/tests-integration/src/bin/test-mem.rs b/tests-integration/src/bin/test-mem.rs index 98aa971ac60..c38c41b4ff2 100644 --- a/tests-integration/src/bin/test-mem.rs +++ b/tests-integration/src/bin/test-mem.rs @@ -1,4 +1,4 @@ -use futures::future::poll_fn; +use std::future::poll_fn; fn main() { let rt = tokio::runtime::Builder::new_multi_thread() diff --git a/tests-integration/tests/process_stdio.rs b/tests-integration/tests/process_stdio.rs index 634099a9d39..df883ef767f 100644 --- a/tests-integration/tests/process_stdio.rs +++ b/tests-integration/tests/process_stdio.rs @@ -206,7 +206,7 @@ async fn vectored_writes() { let mut input = Bytes::from_static(b"hello\n").chain(Bytes::from_static(b"world!\n")); let mut writes_completed = 0; - futures::future::poll_fn(|cx| loop { + std::future::poll_fn(|cx| loop { let mut slices = [IoSlice::new(&[]); 2]; let vectored = input.chunks_vectored(&mut slices); if vectored == 0 { diff --git a/tokio-stream/src/lib.rs b/tokio-stream/src/lib.rs index 21f3fc92943..f2b463bcb9a 100644 --- a/tokio-stream/src/lib.rs +++ b/tokio-stream/src/lib.rs @@ -74,9 +74,6 @@ #[macro_use] mod macros; -mod poll_fn; -pub(crate) use poll_fn::poll_fn; - pub mod wrappers; mod stream_ext; diff --git a/tokio-stream/src/poll_fn.rs b/tokio-stream/src/poll_fn.rs deleted file mode 100644 index 744f22f02b4..00000000000 --- a/tokio-stream/src/poll_fn.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - -pub(crate) struct PollFn { - f: F, -} - -pub(crate) fn poll_fn(f: F) -> PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - PollFn { f } -} - -impl Future for PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - type Output = T; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // Safety: We never construct a `Pin<&mut F>` anywhere, so accessing `f` - // mutably in an unpinned way is sound. - // - // This use of unsafe cannot be replaced with the pin-project macro - // because: - // * If we put `#[pin]` on the field, then it gives us a `Pin<&mut F>`, - // which we can't use to call the closure. - // * If we don't put `#[pin]` on the field, then it makes `PollFn` be - // unconditionally `Unpin`, which we also don't want. - let me = unsafe { Pin::into_inner_unchecked(self) }; - (me.f)(cx) - } -} diff --git a/tokio-stream/src/stream_map.rs b/tokio-stream/src/stream_map.rs index 2f553f91c90..f276f99210e 100644 --- a/tokio-stream/src/stream_map.rs +++ b/tokio-stream/src/stream_map.rs @@ -1,6 +1,7 @@ -use crate::{poll_fn, Stream}; +use crate::Stream; use std::borrow::Borrow; +use std::future::poll_fn; use std::hash::Hash; use std::pin::Pin; use std::task::{ready, Context, Poll}; diff --git a/tokio-util/src/util/poll_buf.rs b/tokio-util/src/util/poll_buf.rs index 0704e7478d2..04985d4922f 100644 --- a/tokio-util/src/util/poll_buf.rs +++ b/tokio-util/src/util/poll_buf.rs @@ -17,7 +17,7 @@ use std::task::{ready, Context, Poll}; /// use tokio_stream as stream; /// use tokio::io::Result; /// use tokio_util::io::{StreamReader, poll_read_buf}; -/// use futures::future::poll_fn; +/// use std::future::poll_fn; /// use std::pin::Pin; /// # #[tokio::main] /// # async fn main() -> std::io::Result<()> { @@ -95,9 +95,9 @@ pub fn poll_read_buf( /// use tokio::fs::File; /// /// use bytes::Buf; +/// use std::future::poll_fn; /// use std::io::Cursor; /// use std::pin::Pin; -/// use futures::future::poll_fn; /// /// #[tokio::main] /// async fn main() -> io::Result<()> { diff --git a/tokio-util/tests/io_inspect.rs b/tokio-util/tests/io_inspect.rs index e6319afcf1b..ee8b3f0c604 100644 --- a/tokio-util/tests/io_inspect.rs +++ b/tokio-util/tests/io_inspect.rs @@ -1,5 +1,5 @@ -use futures::future::poll_fn; use std::{ + future::poll_fn, io::IoSlice, pin::Pin, task::{Context, Poll}, diff --git a/tokio-util/tests/mpsc.rs b/tokio-util/tests/mpsc.rs index cf4dcd55f63..d53c81c2a9a 100644 --- a/tokio-util/tests/mpsc.rs +++ b/tokio-util/tests/mpsc.rs @@ -1,5 +1,5 @@ -use futures::future::poll_fn; use futures::sink::SinkExt; +use std::future::poll_fn; use tokio::sync::mpsc::channel; use tokio_test::task::spawn; use tokio_test::{ diff --git a/tokio-util/tests/poll_semaphore.rs b/tokio-util/tests/poll_semaphore.rs index 28beca19fa3..fe947f9164a 100644 --- a/tokio-util/tests/poll_semaphore.rs +++ b/tokio-util/tests/poll_semaphore.rs @@ -9,7 +9,7 @@ type SemRet = Option; fn semaphore_poll( sem: &mut PollSemaphore, ) -> tokio_test::task::Spawn + '_> { - let fut = futures::future::poll_fn(move |cx| sem.poll_acquire(cx)); + let fut = std::future::poll_fn(move |cx| sem.poll_acquire(cx)); tokio_test::task::spawn(fut) } @@ -17,7 +17,7 @@ fn semaphore_poll_many( sem: &mut PollSemaphore, permits: u32, ) -> tokio_test::task::Spawn + '_> { - let fut = futures::future::poll_fn(move |cx| sem.poll_acquire_many(cx, permits)); + let fut = std::future::poll_fn(move |cx| sem.poll_acquire_many(cx, permits)); tokio_test::task::spawn(fut) } diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index fc0a7294ce7..63dd8af3e98 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -936,7 +936,7 @@ cfg_windows! { impl Inner { async fn complete_inflight(&mut self) { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.poll_complete_inflight(cx)).await; } diff --git a/tokio/src/fs/read_dir.rs b/tokio/src/fs/read_dir.rs index c144f918d01..2e7288adb34 100644 --- a/tokio/src/fs/read_dir.rs +++ b/tokio/src/fs/read_dir.rs @@ -76,7 +76,7 @@ impl ReadDir { /// /// This method is cancellation safe. pub async fn next_entry(&mut self) -> io::Result> { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.poll_next_entry(cx)).await } diff --git a/tokio/src/future/mod.rs b/tokio/src/future/mod.rs index 12b6bbc4945..3cf23642dc0 100644 --- a/tokio/src/future/mod.rs +++ b/tokio/src/future/mod.rs @@ -5,10 +5,6 @@ #[cfg(any(feature = "macros", feature = "process"))] pub(crate) mod maybe_done; -mod poll_fn; -#[allow(unused_imports)] -pub use poll_fn::poll_fn; - cfg_process! { mod try_join; pub(crate) use try_join::try_join3; diff --git a/tokio/src/future/poll_fn.rs b/tokio/src/future/poll_fn.rs deleted file mode 100644 index 074d9438eb4..00000000000 --- a/tokio/src/future/poll_fn.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![allow(dead_code)] - -//! Definition of the `PollFn` adapter combinator. - -use std::fmt; -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - -// This struct is intentionally `!Unpin` when `F` is `!Unpin`. This is to -// mitigate the issue where rust puts noalias on mutable references to the -// `PollFn` type if it is `Unpin`. If the closure has ownership of a future, -// then this "leaks" and the future is affected by noalias too, which we don't -// want. -// -// See this thread for more information: -// -// -// The fact that `PollFn` is not `Unpin` when it shouldn't be is tested in -// `tests/async_send_sync.rs`. - -/// Future for the [`poll_fn`] function. -pub struct PollFn { - f: F, -} - -/// Creates a new future wrapping around a function returning [`Poll`]. -pub fn poll_fn(f: F) -> PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - PollFn { f } -} - -impl fmt::Debug for PollFn { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("PollFn").finish() - } -} - -impl Future for PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - type Output = T; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // Safety: We never construct a `Pin<&mut F>` anywhere, so accessing `f` - // mutably in an unpinned way is sound. - // - // This use of unsafe cannot be replaced with the pin-project macro - // because: - // * If we put `#[pin]` on the field, then it gives us a `Pin<&mut F>`, - // which we can't use to call the closure. - // * If we don't put `#[pin]` on the field, then it makes `PollFn` be - // unconditionally `Unpin`, which we also don't want. - let me = unsafe { Pin::into_inner_unchecked(self) }; - (me.f)(cx) - } -} diff --git a/tokio/src/io/util/copy_bidirectional.rs b/tokio/src/io/util/copy_bidirectional.rs index 73041953bf8..ea40a3b4c95 100644 --- a/tokio/src/io/util/copy_bidirectional.rs +++ b/tokio/src/io/util/copy_bidirectional.rs @@ -1,8 +1,8 @@ use super::copy::CopyBuffer; -use crate::future::poll_fn; use crate::io::{AsyncRead, AsyncWrite}; +use std::future::poll_fn; use std::io; use std::pin::Pin; use std::task::{ready, Context, Poll}; diff --git a/tokio/src/io/util/lines.rs b/tokio/src/io/util/lines.rs index 3de0aeaad98..9472557b498 100644 --- a/tokio/src/io/util/lines.rs +++ b/tokio/src/io/util/lines.rs @@ -67,7 +67,7 @@ where /// # } /// ``` pub async fn next_line(&mut self) -> io::Result> { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| Pin::new(&mut *self).poll_next_line(cx)).await } diff --git a/tokio/src/io/util/split.rs b/tokio/src/io/util/split.rs index c941b04908a..1afd6bbefb9 100644 --- a/tokio/src/io/util/split.rs +++ b/tokio/src/io/util/split.rs @@ -59,7 +59,7 @@ where /// # } /// ``` pub async fn next_segment(&mut self) -> io::Result>> { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| Pin::new(&mut *self).poll_next_segment(cx)).await } diff --git a/tokio/src/macros/support.rs b/tokio/src/macros/support.rs index d077a0823c7..8588f75c323 100644 --- a/tokio/src/macros/support.rs +++ b/tokio/src/macros/support.rs @@ -1,7 +1,8 @@ cfg_macros! { - pub use crate::future::poll_fn; pub use crate::future::maybe_done::maybe_done; + pub use std::future::poll_fn; + #[doc(hidden)] pub fn thread_rng_n(n: u32) -> u32 { crate::runtime::context::thread_rng_n(n) diff --git a/tokio/src/net/tcp/split.rs b/tokio/src/net/tcp/split.rs index 1a1e22253f2..8cf53abf53f 100644 --- a/tokio/src/net/tcp/split.rs +++ b/tokio/src/net/tcp/split.rs @@ -8,10 +8,10 @@ //! split has no associated overhead and enforces all invariants at the type //! level. -use crate::future::poll_fn; use crate::io::{AsyncRead, AsyncWrite, Interest, ReadBuf, Ready}; use crate::net::TcpStream; +use std::future::poll_fn; use std::io; use std::net::{Shutdown, SocketAddr}; use std::pin::Pin; @@ -69,7 +69,7 @@ impl ReadHalf<'_> { /// use tokio::io::{self, ReadBuf}; /// use tokio::net::TcpStream; /// - /// use futures::future::poll_fn; + /// use std::future::poll_fn; /// /// #[tokio::main] /// async fn main() -> io::Result<()> { diff --git a/tokio/src/net/tcp/split_owned.rs b/tokio/src/net/tcp/split_owned.rs index 6771d6497a2..025d2fe73ec 100644 --- a/tokio/src/net/tcp/split_owned.rs +++ b/tokio/src/net/tcp/split_owned.rs @@ -8,11 +8,11 @@ //! split has no associated overhead and enforces all invariants at the type //! level. -use crate::future::poll_fn; use crate::io::{AsyncRead, AsyncWrite, Interest, ReadBuf, Ready}; use crate::net::TcpStream; use std::error::Error; +use std::future::poll_fn; use std::net::{Shutdown, SocketAddr}; use std::pin::Pin; use std::sync::Arc; @@ -124,7 +124,7 @@ impl OwnedReadHalf { /// use tokio::io::{self, ReadBuf}; /// use tokio::net::TcpStream; /// - /// use futures::future::poll_fn; + /// use std::future::poll_fn; /// /// #[tokio::main] /// async fn main() -> io::Result<()> { diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 36eb84cc854..2714592d3a3 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -1,6 +1,6 @@ cfg_not_wasi! { - use crate::future::poll_fn; use crate::net::{to_socket_addrs, ToSocketAddrs}; + use std::future::poll_fn; use std::time::Duration; } @@ -340,7 +340,7 @@ impl TcpStream { /// use tokio::io::{self, ReadBuf}; /// use tokio::net::TcpStream; /// - /// use futures::future::poll_fn; + /// use std::future::poll_fn; /// /// #[tokio::main] /// async fn main() -> io::Result<()> { diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index a8b6479f1f8..466ed21c02e 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -1,4 +1,3 @@ -use crate::future::poll_fn; use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready}; use crate::net::unix::split::{split, ReadHalf, WriteHalf}; use crate::net::unix::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; @@ -6,6 +5,7 @@ use crate::net::unix::ucred::{self, UCred}; use crate::net::unix::SocketAddr; use std::fmt; +use std::future::poll_fn; use std::io::{self, Read, Write}; use std::net::Shutdown; #[cfg(target_os = "android")] diff --git a/tokio/src/runtime/coop.rs b/tokio/src/runtime/coop.rs index e4409ee4312..aaca8b6baa2 100644 --- a/tokio/src/runtime/coop.rs +++ b/tokio/src/runtime/coop.rs @@ -255,7 +255,7 @@ mod test { #[test] fn budgeting() { - use futures::future::poll_fn; + use std::future::poll_fn; use tokio_test::*; assert!(get().0.is_none()); diff --git a/tokio/src/runtime/io/registration.rs b/tokio/src/runtime/io/registration.rs index 00410a121fd..16e79e82515 100644 --- a/tokio/src/runtime/io/registration.rs +++ b/tokio/src/runtime/io/registration.rs @@ -219,7 +219,7 @@ impl Registration { loop { let event = self.readiness(interest).await?; - let coop = crate::future::poll_fn(crate::runtime::coop::poll_proceed).await; + let coop = std::future::poll_fn(crate::runtime::coop::poll_proceed).await; match f() { Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { diff --git a/tokio/src/runtime/scheduler/current_thread/mod.rs b/tokio/src/runtime/scheduler/current_thread/mod.rs index 8cf6463f06d..86670460947 100644 --- a/tokio/src/runtime/scheduler/current_thread/mod.rs +++ b/tokio/src/runtime/scheduler/current_thread/mod.rs @@ -1,4 +1,3 @@ -use crate::future::poll_fn; use crate::loom::sync::atomic::AtomicBool; use crate::loom::sync::Arc; use crate::runtime::driver::{self, Driver}; @@ -15,7 +14,7 @@ use crate::util::{waker_ref, RngSeedGenerator, Wake, WakerRef}; use std::cell::RefCell; use std::collections::VecDeque; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::sync::atomic::Ordering::{AcqRel, Release}; use std::task::Poll::{Pending, Ready}; use std::task::Waker; diff --git a/tokio/src/runtime/tests/loom_local.rs b/tokio/src/runtime/tests/loom_local.rs index 89d025b811c..e3060d72dce 100644 --- a/tokio/src/runtime/tests/loom_local.rs +++ b/tokio/src/runtime/tests/loom_local.rs @@ -23,7 +23,7 @@ fn wake_during_shutdown() { ls.spawn_local(async move { let mut send = Some(send); - let () = futures::future::poll_fn(|cx| { + let () = std::future::poll_fn(|cx| { if let Some(send) = send.take() { send.send(cx.waker().clone()); } diff --git a/tokio/src/runtime/tests/loom_multi_thread.rs b/tokio/src/runtime/tests/loom_multi_thread.rs index 4a06b343a4d..ddd14b7fb3f 100644 --- a/tokio/src/runtime/tests/loom_multi_thread.rs +++ b/tokio/src/runtime/tests/loom_multi_thread.rs @@ -8,7 +8,6 @@ mod yield_now; /// Use `LOOM_MAX_PREEMPTIONS=1` to do a "quick" run as a smoke test. /// /// In order to speed up the C -use crate::future::poll_fn; use crate::runtime::tests::loom_oneshot as oneshot; use crate::runtime::{self, Runtime}; use crate::{spawn, task}; @@ -18,7 +17,7 @@ use loom::sync::atomic::{AtomicBool, AtomicUsize}; use loom::sync::Arc; use pin_project_lite::pin_project; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::pin::Pin; use std::sync::atomic::Ordering::{Relaxed, SeqCst}; use std::task::{ready, Context, Poll}; diff --git a/tokio/src/runtime/tests/loom_multi_thread_alt.rs b/tokio/src/runtime/tests/loom_multi_thread_alt.rs index 01b82f67fe8..3ca1335a207 100644 --- a/tokio/src/runtime/tests/loom_multi_thread_alt.rs +++ b/tokio/src/runtime/tests/loom_multi_thread_alt.rs @@ -10,7 +10,6 @@ mod yield_now; /// Use `LOOM_MAX_PREEMPTIONS=1` to do a "quick" run as a smoke test. /// /// In order to speed up the C -use crate::future::poll_fn; use crate::runtime::tests::loom_oneshot as oneshot; use crate::runtime::{self, Runtime}; use crate::{spawn, task}; @@ -20,7 +19,7 @@ use loom::sync::atomic::{AtomicBool, AtomicUsize}; use loom::sync::Arc; use pin_project_lite::pin_project; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::pin::Pin; use std::sync::atomic::Ordering::{Relaxed, SeqCst}; use std::task::{ready, Context, Poll}; diff --git a/tokio/src/runtime/tests/task.rs b/tokio/src/runtime/tests/task.rs index 4035653283d..ea48b8e5199 100644 --- a/tokio/src/runtime/tests/task.rs +++ b/tokio/src/runtime/tests/task.rs @@ -228,7 +228,7 @@ fn shutdown_immediately() { // Test for https://github.com/tokio-rs/tokio/issues/6729 #[test] fn spawn_niche_in_task() { - use crate::future::poll_fn; + use std::future::poll_fn; use std::task::{Context, Poll, Waker}; with(|rt| { diff --git a/tokio/src/runtime/time/tests/mod.rs b/tokio/src/runtime/time/tests/mod.rs index 0e453433691..a2271b6fb9d 100644 --- a/tokio/src/runtime/time/tests/mod.rs +++ b/tokio/src/runtime/time/tests/mod.rs @@ -54,10 +54,7 @@ fn single_timer() { ); pin!(entry); - block_on(futures::future::poll_fn(|cx| { - entry.as_mut().poll_elapsed(cx) - })) - .unwrap(); + block_on(std::future::poll_fn(|cx| entry.as_mut().poll_elapsed(cx))).unwrap(); }); thread::yield_now(); @@ -126,10 +123,7 @@ fn change_waker() { .as_mut() .poll_elapsed(&mut Context::from_waker(futures::task::noop_waker_ref())); - block_on(futures::future::poll_fn(|cx| { - entry.as_mut().poll_elapsed(cx) - })) - .unwrap(); + block_on(std::future::poll_fn(|cx| entry.as_mut().poll_elapsed(cx))).unwrap(); }); thread::yield_now(); @@ -167,10 +161,7 @@ fn reset_future() { entry.as_mut().reset(start + Duration::from_secs(2), true); // shouldn't complete before 2s - block_on(futures::future::poll_fn(|cx| { - entry.as_mut().poll_elapsed(cx) - })) - .unwrap(); + block_on(std::future::poll_fn(|cx| entry.as_mut().poll_elapsed(cx))).unwrap(); finished_early_.store(true, Ordering::Relaxed); }); diff --git a/tokio/src/signal/mod.rs b/tokio/src/signal/mod.rs index 5778f22ed12..cca3963e113 100644 --- a/tokio/src/signal/mod.rs +++ b/tokio/src/signal/mod.rs @@ -84,7 +84,7 @@ impl RxFuture { } async fn recv(&mut self) -> Option<()> { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.poll_recv(cx)).await } diff --git a/tokio/src/sync/mpsc/bounded.rs b/tokio/src/sync/mpsc/bounded.rs index beda7fe1bf4..a6aecf007ca 100644 --- a/tokio/src/sync/mpsc/bounded.rs +++ b/tokio/src/sync/mpsc/bounded.rs @@ -238,7 +238,7 @@ impl Receiver { /// } /// ``` pub async fn recv(&mut self) -> Option { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.chan.recv(cx)).await } @@ -314,7 +314,7 @@ impl Receiver { /// } /// ``` pub async fn recv_many(&mut self, buffer: &mut Vec, limit: usize) -> usize { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.chan.recv_many(cx, buffer, limit)).await } diff --git a/tokio/src/sync/mpsc/unbounded.rs b/tokio/src/sync/mpsc/unbounded.rs index 47e1b6c7c77..f794f4073d2 100644 --- a/tokio/src/sync/mpsc/unbounded.rs +++ b/tokio/src/sync/mpsc/unbounded.rs @@ -165,7 +165,7 @@ impl UnboundedReceiver { /// } /// ``` pub async fn recv(&mut self) -> Option { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.poll_recv(cx)).await } @@ -239,7 +239,7 @@ impl UnboundedReceiver { /// } /// ``` pub async fn recv_many(&mut self, buffer: &mut Vec, limit: usize) -> usize { - use crate::future::poll_fn; + use std::future::poll_fn; poll_fn(|cx| self.chan.recv_many(cx, buffer, limit)).await } diff --git a/tokio/src/sync/oneshot.rs b/tokio/src/sync/oneshot.rs index 151b9c85c83..2b346eae81c 100644 --- a/tokio/src/sync/oneshot.rs +++ b/tokio/src/sync/oneshot.rs @@ -698,7 +698,7 @@ impl Sender { /// } /// ``` pub async fn closed(&mut self) { - use crate::future::poll_fn; + use std::future::poll_fn; #[cfg(all(tokio_unstable, feature = "tracing"))] let resource_span = self.resource_span.clone(); @@ -775,7 +775,7 @@ impl Sender { /// ``` /// use tokio::sync::oneshot; /// - /// use futures::future::poll_fn; + /// use std::future::poll_fn; /// /// #[tokio::main] /// async fn main() { diff --git a/tokio/src/sync/tests/loom_atomic_waker.rs b/tokio/src/sync/tests/loom_atomic_waker.rs index f8bae65d130..688bf95b662 100644 --- a/tokio/src/sync/tests/loom_atomic_waker.rs +++ b/tokio/src/sync/tests/loom_atomic_waker.rs @@ -1,9 +1,9 @@ use crate::sync::task::AtomicWaker; -use futures::future::poll_fn; use loom::future::block_on; use loom::sync::atomic::AtomicUsize; use loom::thread; +use std::future::poll_fn; use std::sync::atomic::Ordering::Relaxed; use std::sync::Arc; use std::task::Poll::{Pending, Ready}; diff --git a/tokio/src/sync/tests/loom_mpsc.rs b/tokio/src/sync/tests/loom_mpsc.rs index 1dbe5ea419c..039b87a7734 100644 --- a/tokio/src/sync/tests/loom_mpsc.rs +++ b/tokio/src/sync/tests/loom_mpsc.rs @@ -1,9 +1,9 @@ use crate::sync::mpsc; -use futures::future::poll_fn; use loom::future::block_on; use loom::sync::Arc; use loom::thread; +use std::future::poll_fn; use tokio_test::assert_ok; #[test] diff --git a/tokio/src/sync/tests/loom_notify.rs b/tokio/src/sync/tests/loom_notify.rs index a4ded1d35bc..e58a78ff1c7 100644 --- a/tokio/src/sync/tests/loom_notify.rs +++ b/tokio/src/sync/tests/loom_notify.rs @@ -108,8 +108,7 @@ fn notify_multi() { #[test] fn notify_drop() { - use crate::future::poll_fn; - use std::future::Future; + use std::future::{poll_fn, Future}; use std::task::Poll; loom::model(|| { diff --git a/tokio/src/sync/tests/loom_oneshot.rs b/tokio/src/sync/tests/loom_oneshot.rs index 717edcfd2a3..62e1251c26e 100644 --- a/tokio/src/sync/tests/loom_oneshot.rs +++ b/tokio/src/sync/tests/loom_oneshot.rs @@ -1,8 +1,8 @@ use crate::sync::oneshot; -use futures::future::poll_fn; use loom::future::block_on; use loom::thread; +use std::future::poll_fn; use std::task::Poll::{Pending, Ready}; #[test] diff --git a/tokio/src/sync/tests/loom_semaphore_batch.rs b/tokio/src/sync/tests/loom_semaphore_batch.rs index 85cd584d2d4..27a459521ed 100644 --- a/tokio/src/sync/tests/loom_semaphore_batch.rs +++ b/tokio/src/sync/tests/loom_semaphore_batch.rs @@ -1,10 +1,9 @@ use crate::sync::batch_semaphore::*; -use futures::future::poll_fn; use loom::future::block_on; use loom::sync::atomic::AtomicUsize; use loom::thread; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::pin::Pin; use std::sync::atomic::Ordering::SeqCst; use std::sync::Arc; diff --git a/tokio/src/task/consume_budget.rs b/tokio/src/task/consume_budget.rs index 988555b28c6..85ef1bfb2d2 100644 --- a/tokio/src/task/consume_budget.rs +++ b/tokio/src/task/consume_budget.rs @@ -27,7 +27,7 @@ use std::task::{ready, Poll}; pub async fn consume_budget() { let mut status = Poll::Pending; - crate::future::poll_fn(move |cx| { + std::future::poll_fn(move |cx| { ready!(crate::trace::trace_leaf(cx)); if status.is_ready() { return status; diff --git a/tokio/src/task/join_set.rs b/tokio/src/task/join_set.rs index a9cd8f52d55..4bbd1d91a95 100644 --- a/tokio/src/task/join_set.rs +++ b/tokio/src/task/join_set.rs @@ -281,7 +281,7 @@ impl JoinSet { /// statement and some other branch completes first, it is guaranteed that no tasks were /// removed from this `JoinSet`. pub async fn join_next(&mut self) -> Option> { - crate::future::poll_fn(|cx| self.poll_join_next(cx)).await + std::future::poll_fn(|cx| self.poll_join_next(cx)).await } /// Waits until one of the tasks in the set completes and returns its @@ -303,7 +303,7 @@ impl JoinSet { #[cfg(tokio_unstable)] #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] pub async fn join_next_with_id(&mut self) -> Option> { - crate::future::poll_fn(|cx| self.poll_join_next_with_id(cx)).await + std::future::poll_fn(|cx| self.poll_join_next_with_id(cx)).await } /// Tries to join one of the tasks in the set that has completed and return its output. diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 3f3a69fc967..5600f08edcf 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -1238,7 +1238,7 @@ mod tests { })); // poll the run until future once - crate::future::poll_fn(|cx| { + std::future::poll_fn(|cx| { let _ = run_until.as_mut().poll(cx); Poll::Ready(()) }) diff --git a/tokio/src/time/interval.rs b/tokio/src/time/interval.rs index a13030d36a4..0153a567f10 100644 --- a/tokio/src/time/interval.rs +++ b/tokio/src/time/interval.rs @@ -1,8 +1,7 @@ -use crate::future::poll_fn; use crate::time::{sleep_until, Duration, Instant, Sleep}; use crate::util::trace; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::panic::Location; use std::pin::Pin; use std::task::{ready, Context, Poll}; diff --git a/tokio/tests/io_async_fd.rs b/tokio/tests/io_async_fd.rs index f4dcfcf0927..856ac6db19b 100644 --- a/tokio/tests/io_async_fd.rs +++ b/tokio/tests/io_async_fd.rs @@ -400,12 +400,12 @@ async fn poll_fns() { let read_fut = tokio::spawn(async move { // Move waker onto this task first - assert_pending!(poll!(futures::future::poll_fn(|cx| afd_a_2 + assert_pending!(poll!(std::future::poll_fn(|cx| afd_a_2 .as_ref() .poll_read_ready(cx)))); barrier_clone.wait().await; - let _ = futures::future::poll_fn(|cx| afd_a_2.as_ref().poll_read_ready(cx)).await; + let _ = std::future::poll_fn(|cx| afd_a_2.as_ref().poll_read_ready(cx)).await; }); let afd_a_2 = afd_a.clone(); @@ -414,12 +414,12 @@ async fn poll_fns() { let mut write_fut = tokio::spawn(async move { // Move waker onto this task first - assert_pending!(poll!(futures::future::poll_fn(|cx| afd_a_2 + assert_pending!(poll!(std::future::poll_fn(|cx| afd_a_2 .as_ref() .poll_write_ready(cx)))); barrier_clone.wait().await; - let _ = futures::future::poll_fn(|cx| afd_a_2.as_ref().poll_write_ready(cx)).await; + let _ = std::future::poll_fn(|cx| afd_a_2.as_ref().poll_write_ready(cx)).await; }); r_barrier.wait().await; @@ -530,11 +530,11 @@ fn driver_shutdown_wakes_pending_race() { } async fn poll_readable(fd: &AsyncFd) -> std::io::Result> { - futures::future::poll_fn(|cx| fd.poll_read_ready(cx)).await + std::future::poll_fn(|cx| fd.poll_read_ready(cx)).await } async fn poll_writable(fd: &AsyncFd) -> std::io::Result> { - futures::future::poll_fn(|cx| fd.poll_write_ready(cx)).await + std::future::poll_fn(|cx| fd.poll_write_ready(cx)).await } #[test] diff --git a/tokio/tests/io_take.rs b/tokio/tests/io_take.rs index 539f17f3a2d..1ae5f6908f5 100644 --- a/tokio/tests/io_take.rs +++ b/tokio/tests/io_take.rs @@ -33,7 +33,7 @@ async fn issue_4435() { let mut read_buf = ReadBuf::new(&mut buf); read_buf.put_slice(b"AB"); - futures::future::poll_fn(|cx| rd.as_mut().poll_read(cx, &mut read_buf)) + std::future::poll_fn(|cx| rd.as_mut().poll_read(cx, &mut read_buf)) .await .unwrap(); assert_eq!(&buf, &b"ABhell\0\0"[..]); diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index 6c05a3fda0d..fdf7fde1342 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -11,7 +11,7 @@ use tokio::test as maybe_tokio_test; use tokio::sync::oneshot; use tokio_test::{assert_ok, assert_pending, assert_ready}; -use futures::future::poll_fn; +use std::future::poll_fn; use std::task::Poll::Ready; #[maybe_tokio_test] diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 2c4fc9e0c94..12f9e16592f 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -112,8 +112,7 @@ rt_test! { use tokio_test::assert_err; use tokio_test::assert_ok; - use futures::future::poll_fn; - use std::future::Future; + use std::future::{poll_fn, Future}; use std::pin::Pin; #[cfg(not(target_os="wasi"))] @@ -696,7 +695,7 @@ rt_test! { loop { // Don't use Tokio's `yield_now()` to avoid special defer // logic. - futures::future::poll_fn::<(), _>(|cx| { + std::future::poll_fn::<(), _>(|cx| { cx.waker().wake_by_ref(); std::task::Poll::Pending }).await; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index a4742dd234e..b6666616f9f 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -8,8 +8,7 @@ use tokio::runtime; use tokio::sync::oneshot; use tokio_test::{assert_err, assert_ok}; -use futures::future::poll_fn; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::pin::Pin; use std::sync::atomic::Ordering::Relaxed; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/tokio/tests/rt_threaded_alt.rs b/tokio/tests/rt_threaded_alt.rs index 7d723605a27..f7e52af83dd 100644 --- a/tokio/tests/rt_threaded_alt.rs +++ b/tokio/tests/rt_threaded_alt.rs @@ -9,8 +9,7 @@ use tokio::runtime; use tokio::sync::oneshot; use tokio_test::{assert_err, assert_ok}; -use futures::future::poll_fn; -use std::future::Future; +use std::future::{poll_fn, Future}; use std::pin::Pin; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs index d547c48daa3..c72dcea39d6 100644 --- a/tokio/tests/tcp_accept.rs +++ b/tokio/tests/tcp_accept.rs @@ -96,8 +96,7 @@ async fn no_extra_poll() { #[tokio::test] async fn accept_many() { - use futures::future::poll_fn; - use std::future::Future; + use std::future::{poll_fn, Future}; use std::sync::atomic::AtomicBool; const N: usize = 50; diff --git a/tokio/tests/tcp_stream.rs b/tokio/tests/tcp_stream.rs index 725a60169ea..b06628f03a0 100644 --- a/tokio/tests/tcp_stream.rs +++ b/tokio/tests/tcp_stream.rs @@ -7,12 +7,11 @@ use tokio::try_join; use tokio_test::task; use tokio_test::{assert_ok, assert_pending, assert_ready_ok}; +use std::future::poll_fn; use std::io; use std::task::Poll; use std::time::Duration; -use futures::future::poll_fn; - #[tokio::test] async fn set_linger() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/tokio/tests/udp.rs b/tokio/tests/udp.rs index eea281c2316..586ceb42e5b 100644 --- a/tokio/tests/udp.rs +++ b/tokio/tests/udp.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind or UDP -use futures::future::poll_fn; +use std::future::poll_fn; use std::io; use std::sync::Arc; use tokio::{io::ReadBuf, net::UdpSocket}; diff --git a/tokio/tests/uds_datagram.rs b/tokio/tests/uds_datagram.rs index ad22a0b99dd..126af1cac7c 100644 --- a/tokio/tests/uds_datagram.rs +++ b/tokio/tests/uds_datagram.rs @@ -2,11 +2,11 @@ #![cfg(feature = "full")] #![cfg(unix)] -use futures::future::poll_fn; use tokio::io::ReadBuf; use tokio::net::UnixDatagram; use tokio::try_join; +use std::future::poll_fn; use std::io; use std::sync::Arc;