diff --git a/futures-util/src/future/catch_unwind.rs b/futures-util/src/future/catch_unwind.rs index b344ab2116..a5bb3cbf84 100644 --- a/futures-util/src/future/catch_unwind.rs +++ b/futures-util/src/future/catch_unwind.rs @@ -27,9 +27,6 @@ impl Future for CatchUnwind type Output = Result>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match catch_unwind(AssertUnwindSafe(|| self.future().poll(cx))) { - Ok(res) => res.map(Ok), - Err(e) => Poll::Ready(Err(e)) - } + catch_unwind(AssertUnwindSafe(|| self.future().poll(cx)))?.map(Ok) } } diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index 4bdfb4ab9c..ec88f2d209 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -60,9 +60,7 @@ impl, Item> Buffer { ) -> Poll> { ready!(self.as_mut().sink().poll_ready(cx))?; while let Some(item) = self.as_mut().buf().pop_front() { - if let Err(e) = self.as_mut().sink().start_send(item) { - return Poll::Ready(Err(e)); - } + self.as_mut().sink().start_send(item)?; if !self.buf.is_empty() { ready!(self.as_mut().sink().poll_ready(cx))?; } @@ -91,9 +89,7 @@ impl, Item> Sink for Buffer { return self.as_mut().sink().poll_ready(cx); } - if let Poll::Ready(Err(e)) = self.as_mut().try_empty_buffer(cx) { - return Poll::Ready(Err(e)); - } + let _ = self.as_mut().try_empty_buffer(cx)?; if self.buf.len() >= self.capacity { Poll::Pending diff --git a/futures-util/src/sink/send.rs b/futures-util/src/sink/send.rs index 0d3180598a..0effb17545 100644 --- a/futures-util/src/sink/send.rs +++ b/futures-util/src/sink/send.rs @@ -33,13 +33,8 @@ impl + Unpin + ?Sized, Item> Future for Send<'_, Si, Item> { let this = &mut *self; if let Some(item) = this.item.take() { let mut sink = Pin::new(&mut this.sink); - match sink.as_mut().poll_ready(cx) { - Poll::Ready(Ok(())) => { - if let Err(e) = sink.as_mut().start_send(item) { - return Poll::Ready(Err(e)); - } - } - Poll::Ready(Err(e)) => return Poll::Ready(Err(e)), + match sink.as_mut().poll_ready(cx)? { + Poll::Ready(()) => sink.as_mut().start_send(item)?, Poll::Pending => { this.item = Some(item); return Poll::Pending; diff --git a/futures-util/src/sink/send_all.rs b/futures-util/src/sink/send_all.rs index f4c909b97d..e1bf04ca78 100644 --- a/futures-util/src/sink/send_all.rs +++ b/futures-util/src/sink/send_all.rs @@ -47,11 +47,10 @@ where item: St::Item, ) -> Poll> { debug_assert!(self.buffered.is_none()); - match Pin::new(&mut self.sink).poll_ready(cx) { - Poll::Ready(Ok(())) => { + match Pin::new(&mut self.sink).poll_ready(cx)? { + Poll::Ready(()) => { Poll::Ready(Pin::new(&mut self.sink).start_send(item)) } - Poll::Ready(Err(e)) => Poll::Ready(Err(e)), Poll::Pending => { self.buffered = Some(item); Poll::Pending diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 150a6bf551..8ad746708c 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -146,21 +146,15 @@ where mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - match self.as_mut().try_empty_stream(cx) { - Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => self.as_mut().sink().poll_flush(cx), - Poll::Ready(Err(e)) => Poll::Ready(Err(e)), - } + ready!(self.as_mut().try_empty_stream(cx)?); + self.as_mut().sink().poll_flush(cx) } fn poll_close( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - match self.as_mut().try_empty_stream(cx) { - Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => self.as_mut().sink().poll_close(cx), - Poll::Ready(Err(e)) => Poll::Ready(Err(e)), - } + ready!(self.as_mut().try_empty_stream(cx)?); + self.as_mut().sink().poll_close(cx) } } diff --git a/futures-util/src/stream/forward.rs b/futures-util/src/stream/forward.rs index 53253a34d8..862f3534a4 100644 --- a/futures-util/src/stream/forward.rs +++ b/futures-util/src/stream/forward.rs @@ -77,10 +77,9 @@ where } loop { - match self.as_mut().stream().poll_next(cx) { - Poll::Ready(Some(Ok(item))) => + match self.as_mut().stream().poll_next(cx)? { + Poll::Ready(Some(item)) => ready!(self.as_mut().try_start_send(cx, item))?, - Poll::Ready(Some(Err(e))) => return Poll::Ready(Err(e)), Poll::Ready(None) => { ready!(self.as_mut().sink().as_pin_mut().expect(INVALID_POLL).poll_close(cx))?; self.as_mut().sink().set(None); diff --git a/futures-util/src/try_stream/try_buffer_unordered.rs b/futures-util/src/try_stream/try_buffer_unordered.rs index 559230e93c..f6f096aff0 100644 --- a/futures-util/src/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/try_stream/try_buffer_unordered.rs @@ -85,9 +85,8 @@ impl Stream for TryBufferUnordered // First up, try to spawn off as many futures as possible by filling up // our slab of futures. Propagate errors from the stream immediately. while self.in_progress_queue.len() < self.max { - match self.as_mut().stream().poll_next(cx) { - Poll::Ready(Some(Ok(fut))) => self.as_mut().in_progress_queue().push(fut.into_future()), - Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))), + match self.as_mut().stream().poll_next(cx)? { + Poll::Ready(Some(fut)) => self.as_mut().in_progress_queue().push(fut.into_future()), Poll::Ready(None) | Poll::Pending => break, } } diff --git a/futures-util/src/try_stream/try_collect.rs b/futures-util/src/try_stream/try_collect.rs index 71776a24e0..38a5447c91 100644 --- a/futures-util/src/try_stream/try_collect.rs +++ b/futures-util/src/try_stream/try_collect.rs @@ -47,9 +47,8 @@ impl Future for TryCollect cx: &mut Context<'_>, ) -> Poll { loop { - match ready!(self.as_mut().stream().try_poll_next(cx)) { - Some(Ok(x)) => self.as_mut().items().extend(Some(x)), - Some(Err(e)) => return Poll::Ready(Err(e)), + match ready!(self.as_mut().stream().try_poll_next(cx)?) { + Some(x) => self.as_mut().items().extend(Some(x)), None => return Poll::Ready(Ok(self.as_mut().finish())), } } diff --git a/futures-util/src/try_stream/try_concat.rs b/futures-util/src/try_stream/try_concat.rs index f625c6dc2f..447bbf5b13 100644 --- a/futures-util/src/try_stream/try_concat.rs +++ b/futures-util/src/try_stream/try_concat.rs @@ -40,8 +40,8 @@ where fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { loop { - match ready!(self.as_mut().stream().try_poll_next(cx)) { - Some(Ok(x)) => { + match ready!(self.as_mut().stream().try_poll_next(cx)?) { + Some(x) => { let accum = self.as_mut().accum(); if let Some(a) = accum { a.extend(x) @@ -49,7 +49,6 @@ where *accum = Some(x) } }, - Some(Err(e)) => return Poll::Ready(Err(e)), None => { return Poll::Ready(Ok(self.as_mut().accum().take().unwrap_or_default())) } diff --git a/futures-util/src/try_stream/try_filter.rs b/futures-util/src/try_stream/try_filter.rs index a4b66fafc7..65be194f94 100644 --- a/futures-util/src/try_stream/try_filter.rs +++ b/futures-util/src/try_stream/try_filter.rs @@ -95,9 +95,8 @@ impl Stream for TryFilter ) -> Poll>> { loop { if self.pending_fut.is_none() { - let item = match ready!(self.as_mut().stream().try_poll_next(cx)) { - Some(Ok(x)) => x, - Some(Err(e)) => return Poll::Ready(Some(Err(e))), + let item = match ready!(self.as_mut().stream().try_poll_next(cx)?) { + Some(x) => x, None => return Poll::Ready(None), }; let fut = (self.as_mut().f())(&item); diff --git a/futures-util/src/try_stream/try_filter_map.rs b/futures-util/src/try_stream/try_filter_map.rs index ef97a3ce2e..ce5e092fd2 100644 --- a/futures-util/src/try_stream/try_filter_map.rs +++ b/futures-util/src/try_stream/try_filter_map.rs @@ -84,9 +84,8 @@ impl Stream for TryFilterMap ) -> Poll>> { loop { if self.pending.is_none() { - let item = match ready!(self.as_mut().stream().try_poll_next(cx)) { - Some(Ok(x)) => x, - Some(Err(e)) => return Poll::Ready(Some(Err(e))), + let item = match ready!(self.as_mut().stream().try_poll_next(cx)?) { + Some(x) => x, None => return Poll::Ready(None), }; let fut = (self.as_mut().f())(item); @@ -95,10 +94,8 @@ impl Stream for TryFilterMap let result = ready!(self.as_mut().pending().as_pin_mut().unwrap().try_poll(cx)); self.as_mut().pending().set(None); - match result { - Ok(Some(x)) => return Poll::Ready(Some(Ok(x))), - Err(e) => return Poll::Ready(Some(Err(e))), - Ok(None) => {}, + if let Some(x) = result? { + return Poll::Ready(Some(Ok(x))); } } }