Skip to content

Commit

Permalink
chore: use poll_fn from std (#6810)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Sep 5, 2024
1 parent 35f244a commit 12b2567
Show file tree
Hide file tree
Showing 52 changed files with 67 additions and 187 deletions.
2 changes: 1 addition & 1 deletion tests-integration/src/bin/test-mem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::poll_fn;
use std::future::poll_fn;

fn main() {
let rt = tokio::runtime::Builder::new_multi_thread()
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/tests/process_stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions tokio-stream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@
#[macro_use]
mod macros;

mod poll_fn;
pub(crate) use poll_fn::poll_fn;

pub mod wrappers;

mod stream_ext;
Expand Down
35 changes: 0 additions & 35 deletions tokio-stream/src/poll_fn.rs

This file was deleted.

3 changes: 2 additions & 1 deletion tokio-stream/src/stream_map.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions tokio-util/src/util/poll_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -95,9 +95,9 @@ pub fn poll_read_buf<T: AsyncRead + ?Sized, B: BufMut>(
/// 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<()> {
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/io_inspect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use futures::future::poll_fn;
use std::{
future::poll_fn,
io::IoSlice,
pin::Pin,
task::{Context, Poll},
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/mpsc.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
4 changes: 2 additions & 2 deletions tokio-util/tests/poll_semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ type SemRet = Option<OwnedSemaphorePermit>;
fn semaphore_poll(
sem: &mut PollSemaphore,
) -> tokio_test::task::Spawn<impl Future<Output = SemRet> + '_> {
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)
}

fn semaphore_poll_many(
sem: &mut PollSemaphore,
permits: u32,
) -> tokio_test::task::Spawn<impl Future<Output = SemRet> + '_> {
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)
}

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/read_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ReadDir {
///
/// This method is cancellation safe.
pub async fn next_entry(&mut self) -> io::Result<Option<DirEntry>> {
use crate::future::poll_fn;
use std::future::poll_fn;
poll_fn(|cx| self.poll_next_entry(cx)).await
}

Expand Down
4 changes: 0 additions & 4 deletions tokio/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 0 additions & 60 deletions tokio/src/future/poll_fn.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tokio/src/io/util/copy_bidirectional.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
/// # }
/// ```
pub async fn next_line(&mut self) -> io::Result<Option<String>> {
use crate::future::poll_fn;
use std::future::poll_fn;

poll_fn(|cx| Pin::new(&mut *self).poll_next_line(cx)).await
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
/// # }
/// ```
pub async fn next_segment(&mut self) -> io::Result<Option<Vec<u8>>> {
use crate::future::poll_fn;
use std::future::poll_fn;

poll_fn(|cx| Pin::new(&mut *self).poll_next_segment(cx)).await
}
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/macros/support.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/tcp/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<()> {
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/tcp/split_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<()> {
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down Expand Up @@ -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<()> {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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};
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")]
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/coop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/io/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
3 changes: 1 addition & 2 deletions tokio/src/runtime/scheduler/current_thread/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/tests/loom_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 1 addition & 2 deletions tokio/src/runtime/tests/loom_multi_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions tokio/src/runtime/tests/loom_multi_thread_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down
Loading

0 comments on commit 12b2567

Please sign in to comment.