From b7f417d738d89071fe4d2ec880a908d67e19c12c Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Wed, 13 Oct 2021 16:34:53 +0200 Subject: [PATCH] Remove try_poll_next method --- futures-core/src/stream.rs | 27 +------------------ futures-util/src/compat/compat03as01.rs | 2 +- .../src/future/try_future/try_flatten.rs | 2 +- futures-util/src/sink/send_all.rs | 2 +- .../src/stream/try_stream/and_then.rs | 2 +- .../src/stream/try_stream/into_async_read.rs | 6 ++--- .../src/stream/try_stream/into_stream.rs | 2 +- futures-util/src/stream/try_stream/mod.rs | 18 ++----------- futures-util/src/stream/try_stream/or_else.rs | 2 +- .../src/stream/try_stream/try_chunks.rs | 2 +- .../src/stream/try_stream/try_collect.rs | 2 +- .../src/stream/try_stream/try_concat.rs | 2 +- .../src/stream/try_stream/try_filter.rs | 2 +- .../src/stream/try_stream/try_filter_map.rs | 2 +- .../src/stream/try_stream/try_flatten.rs | 4 +-- .../src/stream/try_stream/try_next.rs | 4 +-- .../src/stream/try_stream/try_skip_while.rs | 4 +-- .../src/stream/try_stream/try_take_while.rs | 2 +- 18 files changed, 24 insertions(+), 63 deletions(-) diff --git a/futures-core/src/stream.rs b/futures-core/src/stream.rs index ad5350b795..b236f8105b 100644 --- a/futures-core/src/stream.rs +++ b/futures-core/src/stream.rs @@ -154,32 +154,14 @@ where } } -mod private_try_stream { - use super::Stream; - - pub trait Sealed {} - - impl Sealed for S where S: ?Sized + Stream> {} -} - /// A convenience for streams that return `Result` values that includes /// a variety of adapters tailored to such futures. -pub trait TryStream: Stream + private_try_stream::Sealed { +pub trait TryStream: Stream> { /// The type of successful values yielded by this future type Ok; /// The type of failures yielded by this future type Error; - - /// Poll this `TryStream` as if it were a `Stream`. - /// - /// 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 Context<'_>, - ) -> Poll>>; } impl TryStream for S @@ -188,13 +170,6 @@ where { type Ok = T; type Error = E; - - fn try_poll_next( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll>> { - self.poll_next(cx) - } } #[cfg(feature = "alloc")] diff --git a/futures-util/src/compat/compat03as01.rs b/futures-util/src/compat/compat03as01.rs index 2573fe7a74..d0eff023b6 100644 --- a/futures-util/src/compat/compat03as01.rs +++ b/futures-util/src/compat/compat03as01.rs @@ -114,7 +114,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, cx| match inner.poll_next(cx)? { task03::Poll::Ready(None) => Ok(Async01::Ready(None)), task03::Poll::Ready(Some(t)) => Ok(Async01::Ready(Some(t))), task03::Poll::Pending => Ok(Async01::NotReady), diff --git a/futures-util/src/future/try_future/try_flatten.rs b/futures-util/src/future/try_future/try_flatten.rs index 1ce4559ac2..1ded76e9af 100644 --- a/futures-util/src/future/try_future/try_flatten.rs +++ b/futures-util/src/future/try_future/try_flatten.rs @@ -95,7 +95,7 @@ where } }, TryFlattenProj::Second { f } => { - let output = ready!(f.try_poll_next(cx)); + let output = ready!(f.poll_next(cx)); if output.is_none() { self.set(Self::Empty); } diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index e990cecae4..7150feed10 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -81,7 +81,7 @@ where loop { let this = self.as_mut().project(); - match this.stream.try_poll_next(cx)? { + match this.stream.poll_next(cx)? { Poll::Ready(Some(item)) => ready!(self.as_mut().try_start_send(cx, item))?, Poll::Ready(None) => { ready!(Pin::new(this.sink).poll_flush(cx))?; diff --git a/futures-util/src/stream/try_stream/and_then.rs b/futures-util/src/stream/try_stream/and_then.rs index a7b50db0b1..54ed44d031 100644 --- a/futures-util/src/stream/try_stream/and_then.rs +++ b/futures-util/src/stream/try_stream/and_then.rs @@ -62,7 +62,7 @@ where let item = ready!(fut.try_poll(cx)); this.future.set(None); break Some(item); - } else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)?) { this.future.set(Some((this.f)(item))); } else { break None; diff --git a/futures-util/src/stream/try_stream/into_async_read.rs b/futures-util/src/stream/try_stream/into_async_read.rs index 914b277a02..6024f9501a 100644 --- a/futures-util/src/stream/try_stream/into_async_read.rs +++ b/futures-util/src/stream/try_stream/into_async_read.rs @@ -1,4 +1,4 @@ -use crate::stream::TryStreamExt; +use crate::stream::StreamExt; use core::pin::Pin; use futures_core::ready; use futures_core::stream::TryStream; @@ -69,7 +69,7 @@ where return Poll::Ready(Ok(len)); } - ReadState::PendingChunk => match ready!(self.stream.try_poll_next_unpin(cx)) { + ReadState::PendingChunk => match ready!(self.stream.poll_next_unpin(cx)) { Some(Ok(chunk)) => { if !chunk.as_ref().is_empty() { self.state = ReadState::Ready { chunk, chunk_start: 0 }; @@ -121,7 +121,7 @@ where { fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { while let ReadState::PendingChunk = self.state { - match ready!(self.stream.try_poll_next_unpin(cx)) { + match ready!(self.stream.poll_next_unpin(cx)) { Some(Ok(chunk)) => { if !chunk.as_ref().is_empty() { self.state = ReadState::Ready { chunk, chunk_start: 0 }; diff --git a/futures-util/src/stream/try_stream/into_stream.rs b/futures-util/src/stream/try_stream/into_stream.rs index 2126258af7..69a7c95e73 100644 --- a/futures-util/src/stream/try_stream/into_stream.rs +++ b/futures-util/src/stream/try_stream/into_stream.rs @@ -35,7 +35,7 @@ impl Stream for IntoStream { #[inline] fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.project().stream.try_poll_next(cx) + self.project().stream.poll_next(cx) } fn size_hint(&self) -> (usize, Option) { diff --git a/futures-util/src/stream/try_stream/mod.rs b/futures-util/src/stream/try_stream/mod.rs index d69815f7bd..4258047674 100644 --- a/futures-util/src/stream/try_stream/mod.rs +++ b/futures-util/src/stream/try_stream/mod.rs @@ -829,10 +829,10 @@ pub trait TryStreamExt: TryStream { /// /// let mut buffered = stream_of_futures.try_buffered(10); /// - /// assert!(buffered.try_poll_next_unpin(cx).is_pending()); + /// assert!(buffered.poll_next_unpin(cx).is_pending()); /// /// send_two.send(2i32)?; - /// assert!(buffered.try_poll_next_unpin(cx).is_pending()); + /// assert!(buffered.poll_next_unpin(cx).is_pending()); /// Ok::<_, i32>(buffered) /// }).await?; /// @@ -873,20 +873,6 @@ pub trait TryStreamExt: TryStream { )) } - // TODO: false positive warning from rustdoc. Verify once #43466 settles - // - /// A convenience method for calling [`TryStream::try_poll_next`] on [`Unpin`] - /// stream types. - fn try_poll_next_unpin( - &mut self, - cx: &mut Context<'_>, - ) -> Poll>> - where - Self: Unpin, - { - Pin::new(self).try_poll_next(cx) - } - /// Wraps a [`TryStream`] into a stream compatible with libraries using /// futures 0.1 `Stream`. Requires the `compat` feature to be enabled. /// ``` diff --git a/futures-util/src/stream/try_stream/or_else.rs b/futures-util/src/stream/try_stream/or_else.rs index cb69e81323..6bfa0e5a2f 100644 --- a/futures-util/src/stream/try_stream/or_else.rs +++ b/futures-util/src/stream/try_stream/or_else.rs @@ -63,7 +63,7 @@ where this.future.set(None); break Some(item); } else { - match ready!(this.stream.as_mut().try_poll_next(cx)) { + match ready!(this.stream.as_mut().poll_next(cx)) { Some(Ok(item)) => break Some(Ok(item)), Some(Err(e)) => { this.future.set(Some((this.f)(e))); diff --git a/futures-util/src/stream/try_stream/try_chunks.rs b/futures-util/src/stream/try_stream/try_chunks.rs index 07d4425a81..8edecff002 100644 --- a/futures-util/src/stream/try_stream/try_chunks.rs +++ b/futures-util/src/stream/try_stream/try_chunks.rs @@ -48,7 +48,7 @@ impl Stream for TryChunks { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let mut this = self.as_mut().project(); loop { - match ready!(this.stream.as_mut().try_poll_next(cx)) { + match ready!(this.stream.as_mut().poll_next(cx)) { // 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/try_stream/try_collect.rs b/futures-util/src/stream/try_stream/try_collect.rs index 5d3b3d7668..c32f1b46a4 100644 --- a/futures-util/src/stream/try_stream/try_collect.rs +++ b/futures-util/src/stream/try_stream/try_collect.rs @@ -43,7 +43,7 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.project(); Poll::Ready(Ok(loop { - match ready!(this.stream.as_mut().try_poll_next(cx)?) { + match ready!(this.stream.as_mut().poll_next(cx)?) { Some(x) => this.items.extend(Some(x)), None => break mem::replace(this.items, Default::default()), } diff --git a/futures-util/src/stream/try_stream/try_concat.rs b/futures-util/src/stream/try_stream/try_concat.rs index 58fb6a5413..28c789f5f3 100644 --- a/futures-util/src/stream/try_stream/try_concat.rs +++ b/futures-util/src/stream/try_stream/try_concat.rs @@ -37,7 +37,7 @@ where let mut this = self.project(); Poll::Ready(Ok(loop { - if let Some(x) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + if let Some(x) = ready!(this.stream.as_mut().poll_next(cx)?) { if let Some(a) = this.accum { a.extend(x) } else { diff --git a/futures-util/src/stream/try_stream/try_filter.rs b/futures-util/src/stream/try_stream/try_filter.rs index 61e6105c37..0633471c66 100644 --- a/futures-util/src/stream/try_stream/try_filter.rs +++ b/futures-util/src/stream/try_stream/try_filter.rs @@ -80,7 +80,7 @@ where break this.pending_item.take().map(Ok); } *this.pending_item = None; - } else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)?) { this.pending_fut.set(Some((this.f)(&item))); *this.pending_item = Some(item); } else { diff --git a/futures-util/src/stream/try_stream/try_filter_map.rs b/futures-util/src/stream/try_stream/try_filter_map.rs index bb1b5b9db6..d293a3a703 100644 --- a/futures-util/src/stream/try_stream/try_filter_map.rs +++ b/futures-util/src/stream/try_stream/try_filter_map.rs @@ -73,7 +73,7 @@ where if item.is_some() { break item.map(Ok); } - } else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)?) { // No item in progress, but the stream is still going this.pending.set(Some((this.f)(item))); } else { diff --git a/futures-util/src/stream/try_stream/try_flatten.rs b/futures-util/src/stream/try_stream/try_flatten.rs index 4fc04a07bb..b6556832c0 100644 --- a/futures-util/src/stream/try_stream/try_flatten.rs +++ b/futures-util/src/stream/try_stream/try_flatten.rs @@ -58,12 +58,12 @@ where Poll::Ready(loop { if let Some(s) = this.next.as_mut().as_pin_mut() { - if let Some(item) = ready!(s.try_poll_next(cx)?) { + if let Some(item) = ready!(s.poll_next(cx)?) { break Some(Ok(item)); } else { this.next.set(None); } - } else if let Some(s) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(s) = ready!(this.stream.as_mut().poll_next(cx)?) { this.next.set(Some(s)); } else { break None; diff --git a/futures-util/src/stream/try_stream/try_next.rs b/futures-util/src/stream/try_stream/try_next.rs index 13fcf80cae..7866d19acb 100644 --- a/futures-util/src/stream/try_stream/try_next.rs +++ b/futures-util/src/stream/try_stream/try_next.rs @@ -1,4 +1,4 @@ -use crate::stream::TryStreamExt; +use crate::stream::StreamExt; use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::stream::{FusedStream, TryStream}; @@ -29,6 +29,6 @@ impl Future for TryNext<'_, St> { type Output = Result, St::Error>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.stream.try_poll_next_unpin(cx)?.map(Ok) + self.stream.poll_next_unpin(cx)?.map(Ok) } } diff --git a/futures-util/src/stream/try_stream/try_skip_while.rs b/futures-util/src/stream/try_stream/try_skip_while.rs index a424b6c5b1..06e36b61dd 100644 --- a/futures-util/src/stream/try_stream/try_skip_while.rs +++ b/futures-util/src/stream/try_stream/try_skip_while.rs @@ -64,7 +64,7 @@ where let mut this = self.project(); if *this.done_skipping { - return this.stream.try_poll_next(cx); + return this.stream.poll_next(cx); } Poll::Ready(loop { @@ -77,7 +77,7 @@ where *this.done_skipping = true; break item.map(Ok); } - } else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)?) { this.pending_fut.set(Some((this.f)(&item))); *this.pending_item = Some(item); } else { diff --git a/futures-util/src/stream/try_stream/try_take_while.rs b/futures-util/src/stream/try_stream/try_take_while.rs index 3375960ef4..4f6c273c9e 100644 --- a/futures-util/src/stream/try_stream/try_take_while.rs +++ b/futures-util/src/stream/try_stream/try_take_while.rs @@ -82,7 +82,7 @@ where *this.done_taking = true; break None; } - } else if let Some(item) = ready!(this.stream.as_mut().try_poll_next(cx)?) { + } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)?) { this.pending_fut.set(Some((this.f)(&item))); *this.pending_item = Some(item); } else {