Skip to content

Commit

Permalink
util: replace sync::reusable_box::Pending with `std::future::Pendin…
Browse files Browse the repository at this point in the history
…g` (#6000)
  • Loading branch information
victor-timofei authored Sep 11, 2023
1 parent 61042b4 commit 65e7715
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions tokio-util/src/sync/reusable_box.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::alloc::Layout;
use std::fmt;
use std::future::Future;
use std::marker::PhantomData;
use std::future::{self, Future};
use std::mem::{self, ManuallyDrop};
use std::pin::Pin;
use std::ptr;
Expand Down Expand Up @@ -61,7 +60,7 @@ impl<'a, T> ReusableBoxFuture<'a, T> {
F: Future + Send + 'a,
{
// future::Pending<T> is a ZST so this never allocates.
let boxed = mem::replace(&mut this.boxed, Box::pin(Pending(PhantomData)));
let boxed = mem::replace(&mut this.boxed, Box::pin(future::pending()));
reuse_pin_box(boxed, future, |boxed| this.boxed = Pin::from(boxed))
}

Expand Down Expand Up @@ -156,16 +155,3 @@ impl<O, F: FnOnce() -> O> Drop for CallOnDrop<O, F> {
f();
}
}

/// The same as `std::future::Pending<T>`; we can't use that type directly because on rustc
/// versions <1.60 it didn't unconditionally implement `Send`.
// FIXME: use `std::future::Pending<T>` once the MSRV is >=1.60
struct Pending<T>(PhantomData<fn() -> T>);

impl<T> Future for Pending<T> {
type Output = T;

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Pending
}
}

0 comments on commit 65e7715

Please sign in to comment.