From ec532df410c77b8ab5f0b1765f5282eee2e2b2d8 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Sat, 4 Feb 2023 07:56:09 +0800 Subject: [PATCH] Poll `Select` futures without moving them (#2704) --- futures-util/src/future/select.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/futures-util/src/future/select.rs b/futures-util/src/future/select.rs index e693a30b00..80b67e670d 100644 --- a/futures-util/src/future/select.rs +++ b/futures-util/src/future/select.rs @@ -99,17 +99,16 @@ where type Output = Either<(A::Output, B), (B::Output, A)>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let (mut a, mut b) = self.inner.take().expect("cannot poll Select twice"); + let (a, b) = self.inner.as_mut().expect("cannot poll Select twice"); if let Poll::Ready(val) = a.poll_unpin(cx) { - return Poll::Ready(Either::Left((val, b))); + return Poll::Ready(Either::Left((val, self.inner.take().unwrap().1))); } if let Poll::Ready(val) = b.poll_unpin(cx) { - return Poll::Ready(Either::Right((val, a))); + return Poll::Ready(Either::Right((val, self.inner.take().unwrap().0))); } - self.inner = Some((a, b)); Poll::Pending } }