Skip to content

Commit

Permalink
Remove try_poll
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Barber committed Jul 19, 2023
1 parent 60bcaed commit 75e53ff
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 55 deletions.
21 changes: 4 additions & 17 deletions futures-core/src/future.rs
Expand Up @@ -2,7 +2,6 @@

use core::ops::DerefMut;
use core::pin::Pin;
use core::task::{Context, Poll};

#[doc(no_inline)]
pub use core::future::Future;
Expand All @@ -20,10 +19,10 @@ pub type LocalBoxFuture<'a, T> = Pin<alloc::boxed::Box<dyn Future<Output = T> +
/// should no longer be polled.
///
/// `is_terminated` will return `true` if a future should no longer be polled.
/// Usually, this state occurs after `poll` (or `try_poll`) returned
/// `Poll::Ready`. However, `is_terminated` may also return `true` if a future
/// has become inactive and can no longer make progress and should be ignored
/// or dropped rather than being `poll`ed again.
/// Usually, this state occurs after `poll` returned `Poll::Ready`. However,
/// `is_terminated` may also return `true` if a future has become inactive
/// and can no longer make progress and should be ignored or dropped rather
/// than being `poll`ed again.
pub trait FusedFuture: Future {
/// Returns `true` if the underlying future should no longer be polled.
fn is_terminated(&self) -> bool;
Expand Down Expand Up @@ -63,13 +62,6 @@ pub trait TryFuture:

/// The type of failures yielded by this future
type Error;

/// Poll this `TryFuture` as if it were a `Future`.
///
/// This method is a stopgap for a compiler limitation that prevents us from
/// directly inheriting from the `Future` trait; in the future it won't be
/// needed.
fn try_poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<Self::Ok, Self::Error>>;
}

impl<F, T, E> TryFuture for F
Expand All @@ -78,11 +70,6 @@ where
{
type Ok = T;
type Error = E;

#[inline]
fn try_poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.poll(cx)
}
}

#[cfg(feature = "alloc")]
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/compat/compat03as01.rs
Expand Up @@ -102,7 +102,7 @@ where
type Error = Fut::Error;

fn poll(&mut self) -> Poll01<Self::Item, Self::Error> {
with_context(self, |inner, cx| poll_03_to_01(inner.try_poll(cx)))
with_context(self, |inner, cx| poll_03_to_01(inner.poll(cx)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/future/select_ok.rs
@@ -1,5 +1,5 @@
use super::assert_future;
use crate::future::TryFutureExt;
use crate::future::FutureExt;
use alloc::vec::Vec;
use core::iter::FromIterator;
use core::mem;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<Fut: TryFuture + Unpin> Future for SelectOk<Fut> {
// loop until we've either exhausted all errors, a success was hit, or nothing is ready
loop {
let item =
self.inner.iter_mut().enumerate().find_map(|(i, f)| match f.try_poll_unpin(cx) {
self.inner.iter_mut().enumerate().find_map(|(i, f)| match f.poll_unpin(cx) {
Poll::Pending => None,
Poll::Ready(e) => Some((i, e)),
});
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/try_future/into_future.rs
Expand Up @@ -31,6 +31,6 @@ impl<Fut: TryFuture> Future for IntoFuture<Fut> {

#[inline]
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().future.try_poll(cx)
self.project().future.poll(cx)
}
}
16 changes: 1 addition & 15 deletions futures-util/src/future/try_future/mod.rs
Expand Up @@ -5,12 +5,7 @@

#[cfg(feature = "compat")]
use crate::compat::Compat;
use core::pin::Pin;
use futures_core::{
future::TryFuture,
stream::TryStream,
task::{Context, Poll},
};
use futures_core::{future::TryFuture, stream::TryStream};
#[cfg(feature = "sink")]
use futures_sink::Sink;

Expand Down Expand Up @@ -613,13 +608,4 @@ pub trait TryFutureExt: TryFuture {
{
assert_future::<Result<Self::Ok, Self::Error>, _>(IntoFuture::new(self))
}

/// A convenience method for calling [`TryFuture::try_poll`] on [`Unpin`]
/// future types.
fn try_poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<Self::Ok, Self::Error>>
where
Self: Unpin,
{
Pin::new(self).try_poll(cx)
}
}
8 changes: 4 additions & 4 deletions futures-util/src/future/try_future/try_flatten.rs
Expand Up @@ -43,15 +43,15 @@ where
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(loop {
match self.as_mut().project() {
TryFlattenProj::First { f } => match ready!(f.try_poll(cx)) {
TryFlattenProj::First { f } => match ready!(f.poll(cx)) {
Ok(f) => self.set(Self::Second { f }),
Err(e) => {
self.set(Self::Empty);
break Err(e);
}
},
TryFlattenProj::Second { f } => {
let output = ready!(f.try_poll(cx));
let output = ready!(f.poll(cx));
self.set(Self::Empty);
break output;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ where
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Ready(loop {
match self.as_mut().project() {
TryFlattenProj::First { f } => match ready!(f.try_poll(cx)) {
TryFlattenProj::First { f } => match ready!(f.poll(cx)) {
Ok(f) => self.set(Self::Second { f }),
Err(e) => {
self.set(Self::Empty);
Expand Down Expand Up @@ -112,7 +112,7 @@ where
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(loop {
match self.as_mut().project() {
TryFlattenProj::First { f } => match ready!(f.try_poll(cx)) {
TryFlattenProj::First { f } => match ready!(f.poll(cx)) {
Ok(f) => self.set(Self::Second { f }),
Err(e) => {
self.set(Self::Empty);
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/future/try_future/try_flatten_err.rs
Expand Up @@ -40,15 +40,15 @@ where
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Poll::Ready(loop {
match self.as_mut().project() {
TryFlattenErrProj::First { f } => match ready!(f.try_poll(cx)) {
TryFlattenErrProj::First { f } => match ready!(f.poll(cx)) {
Err(f) => self.set(Self::Second { f }),
Ok(e) => {
self.set(Self::Empty);
break Ok(e);
}
},
TryFlattenErrProj::Second { f } => {
let output = ready!(f.try_poll(cx));
let output = ready!(f.poll(cx));
self.set(Self::Empty);
break output;
}
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/try_join_all.rs
Expand Up @@ -158,7 +158,7 @@ where
let mut state = FinalState::AllDone;

for elem in join_all::iter_pin_mut(elems.as_mut()) {
match elem.try_poll(cx) {
match elem.poll(cx) {
Poll::Pending => state = FinalState::Pending,
Poll::Ready(Ok(())) => {}
Poll::Ready(Err(e)) => {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/try_maybe_done.rs
Expand Up @@ -76,7 +76,7 @@ impl<Fut: TryFuture> Future for TryMaybeDone<Fut> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
unsafe {
match self.as_mut().get_unchecked_mut() {
TryMaybeDone::Future(f) => match ready!(Pin::new_unchecked(f).try_poll(cx)) {
TryMaybeDone::Future(f) => match ready!(Pin::new_unchecked(f).poll(cx)) {
Ok(res) => self.set(Self::Done(res)),
Err(e) => {
self.set(Self::Gone);
Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/future/try_select.rs
@@ -1,4 +1,4 @@
use crate::future::{Either, TryFutureExt};
use crate::future::{Either, FutureExt};
use core::pin::Pin;
use futures_core::future::{Future, TryFuture};
use futures_core::task::{Context, Poll};
Expand Down Expand Up @@ -69,10 +69,10 @@ where

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let (mut a, mut b) = self.inner.take().expect("cannot poll Select twice");
match a.try_poll_unpin(cx) {
match a.poll_unpin(cx) {
Poll::Ready(Err(x)) => Poll::Ready(Err(Either::Left((x, b)))),
Poll::Ready(Ok(x)) => Poll::Ready(Ok(Either::Left((x, b)))),
Poll::Pending => match b.try_poll_unpin(cx) {
Poll::Pending => match b.poll_unpin(cx) {
Poll::Ready(Err(x)) => Poll::Ready(Err(Either::Right((x, a)))),
Poll::Ready(Ok(x)) => Poll::Ready(Ok(Either::Right((x, a)))),
Poll::Pending => {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/stream/try_fold.rs
Expand Up @@ -70,7 +70,7 @@ where
Poll::Ready(loop {
if let Some(fut) = this.future.as_mut().as_pin_mut() {
// we're currently processing a future to produce a new accum value
let res = ready!(fut.try_poll(cx));
let res = ready!(fut.poll(cx));
this.future.set(None);
match res {
Ok(a) => *this.accum = Some(a),
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/stream/try_for_each.rs
Expand Up @@ -54,7 +54,7 @@ where
let mut this = self.project();
loop {
if let Some(fut) = this.future.as_mut().as_pin_mut() {
ready!(fut.try_poll(cx))?;
ready!(fut.poll(cx))?;
this.future.set(None);
} else {
match ready!(this.stream.as_mut().poll_next(cx)) {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/and_then.rs
Expand Up @@ -59,7 +59,7 @@ where

Poll::Ready(loop {
if let Some(fut) = this.future.as_mut().as_pin_mut() {
let item = ready!(fut.try_poll(cx));
let item = ready!(fut.poll(cx));
this.future.set(None);
break Some(item);
} else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/or_else.rs
Expand Up @@ -59,7 +59,7 @@ where

Poll::Ready(loop {
if let Some(fut) = this.future.as_mut().as_pin_mut() {
let item = ready!(fut.try_poll(cx));
let item = ready!(fut.poll(cx));
this.future.set(None);
break Some(item);
} else {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/try_filter_map.rs
Expand Up @@ -67,7 +67,7 @@ where
Poll::Ready(loop {
if let Some(p) = this.pending.as_mut().as_pin_mut() {
// We have an item in progress, poll that until it's done
let res = ready!(p.try_poll(cx));
let res = ready!(p.poll(cx));
this.pending.set(None);
let item = res?;
if item.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/try_skip_while.rs
Expand Up @@ -69,7 +69,7 @@ where

Poll::Ready(loop {
if let Some(fut) = this.pending_fut.as_mut().as_pin_mut() {
let res = ready!(fut.try_poll(cx));
let res = ready!(fut.poll(cx));
this.pending_fut.set(None);
let skipped = res?;
let item = this.pending_item.take();
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/try_take_while.rs
Expand Up @@ -72,7 +72,7 @@ where

Poll::Ready(loop {
if let Some(fut) = this.pending_fut.as_mut().as_pin_mut() {
let res = ready!(fut.try_poll(cx));
let res = ready!(fut.poll(cx));
this.pending_fut.set(None);
let take = res?;
let item = this.pending_item.take();
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/stream/try_stream/try_unfold.rs
Expand Up @@ -105,7 +105,7 @@ where
Poll::Ready(None)
}
Some(future) => {
let step = ready!(future.try_poll(cx));
let step = ready!(future.poll(cx));
this.fut.set(None);

match step {
Expand Down

0 comments on commit 75e53ff

Please sign in to comment.