diff --git a/futures-util/src/future/fuse.rs b/futures-util/src/future/fuse.rs index cee7e590ba..ab3c49102f 100644 --- a/futures-util/src/future/fuse.rs +++ b/futures-util/src/future/fuse.rs @@ -1,5 +1,5 @@ use core::pin::Pin; -use futures_core::future::{Future, FusedFuture}; +use futures_core::future::{FusedFuture, Future}; use futures_core::task::{LocalWaker, Poll}; use pin_utils::unsafe_pinned; @@ -22,9 +22,7 @@ impl Fuse { unsafe_pinned!(future: Option); pub(super) fn new(f: Fut) -> Fuse { - Fuse { - future: Some(f), - } + Fuse { future: Some(f) } } } @@ -44,13 +42,13 @@ impl Future for Fuse { // safety: this re-pinned future will never move before being dropped match fut.poll(lw) { Poll::Pending => return Poll::Pending, - Poll::Ready(v) => v + Poll::Ready(v) => v, } } None => return Poll::Pending, }; - Pin::set(self.as_mut().future(), None); + Pin::set(&mut self.as_mut().future(), None); Poll::Ready(v) } } diff --git a/futures-util/src/future/into_stream.rs b/futures-util/src/future/into_stream.rs index 0b183557f5..33493cfb6e 100644 --- a/futures-util/src/future/into_stream.rs +++ b/futures-util/src/future/into_stream.rs @@ -9,7 +9,7 @@ use pin_utils::unsafe_pinned; #[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct IntoStream { - future: Option + future: Option, } impl IntoStream { @@ -17,7 +17,7 @@ impl IntoStream { pub(super) fn new(future: Fut) -> IntoStream { IntoStream { - future: Some(future) + future: Some(future), } } } @@ -25,18 +25,19 @@ impl IntoStream { impl Stream for IntoStream { type Item = Fut::Output; - fn poll_next(mut self: Pin<&mut Self>, lw: &LocalWaker) -> Poll> { + fn poll_next( + mut self: Pin<&mut Self>, + lw: &LocalWaker, + ) -> Poll> { let v = match self.as_mut().future().as_pin_mut() { - Some(fut) => { - match fut.poll(lw) { - Poll::Pending => return Poll::Pending, - Poll::Ready(v) => v - } - } + Some(fut) => match fut.poll(lw) { + Poll::Pending => return Poll::Pending, + Poll::Ready(v) => v, + }, None => return Poll::Ready(None), }; - Pin::set(self.as_mut().future(), None); + Pin::set(&mut self.as_mut().future(), None); Poll::Ready(Some(v)) } } diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index 6860d666a4..c5f7b2af43 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -107,7 +107,7 @@ impl Future for MaybeDone { MaybeDone::Gone => panic!("MaybeDone polled after value taken"), } }; - Pin::set(self, MaybeDone::Done(res)); + Pin::set(&mut self, MaybeDone::Done(res)); Poll::Ready(()) } } diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 11f3669f2d..ae3131ca45 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -1,4 +1,4 @@ -use core::marker::{Unpin, PhantomData}; +use core::marker::{PhantomData, Unpin}; use core::pin::Pin; use futures_core::stream::Stream; use futures_core::task::{LocalWaker, Poll}; @@ -28,7 +28,8 @@ where Si: Sink + Unpin, F: FnMut(U) -> St, St: Stream> + Unpin, -{} +{ +} impl WithFlatMap where @@ -78,8 +79,12 @@ where self: Pin<&mut Self>, lw: &LocalWaker, ) -> Poll> { - let WithFlatMap { sink, stream, buffer, .. } = - unsafe { Pin::get_unchecked_mut(self) }; + let WithFlatMap { + sink, + stream, + buffer, + .. + } = unsafe { Pin::get_unchecked_mut(self) }; let mut sink = unsafe { Pin::new_unchecked(sink) }; let mut stream = unsafe { Pin::new_unchecked(stream) }; @@ -102,7 +107,7 @@ where }; } } - Pin::set(stream, None); + Pin::set(&mut stream, None); Poll::Ready(Ok(())) } } diff --git a/futures-util/src/stream/unfold.rs b/futures-util/src/stream/unfold.rs index f84a88b089..5dd676e6fb 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -49,8 +49,9 @@ use pin_utils::{unsafe_pinned, unsafe_unpinned}; /// assert_eq!(result, vec![0, 2, 4]); /// ``` pub fn unfold(init: T, f: F) -> Unfold - where F: FnMut(T) -> Fut, - Fut: Future>, +where + F: FnMut(T) -> Fut, + Fut: Future>, { Unfold { f, @@ -85,18 +86,19 @@ impl FusedStream for Unfold { } impl Stream for Unfold - where F: FnMut(T) -> Fut, - Fut: Future>, +where + F: FnMut(T) -> Fut, + Fut: Future>, { type Item = It; fn poll_next( mut self: Pin<&mut Self>, - lw: &LocalWaker + lw: &LocalWaker, ) -> Poll> { if let Some(state) = self.as_mut().state().take() { let fut = (self.as_mut().f())(state); - Pin::set(self.as_mut().fut(), Some(fut)); + Pin::set(&mut self.as_mut().fut(), Some(fut)); } let step = ready!(self.as_mut().fut().as_pin_mut().unwrap().poll(lw)); @@ -104,9 +106,9 @@ impl Stream for Unfold if let Some((item, next_state)) = step { *self.as_mut().state() = Some(next_state); - return Poll::Ready(Some(item)) + return Poll::Ready(Some(item)); } else { - return Poll::Ready(None) + return Poll::Ready(None); } } } diff --git a/futures-util/src/try_future/flatten_sink.rs b/futures-util/src/try_future/flatten_sink.rs index 1d1f07a971..b2a4302030 100644 --- a/futures-util/src/try_future/flatten_sink.rs +++ b/futures-util/src/try_future/flatten_sink.rs @@ -30,7 +30,7 @@ where #[allow(clippy::needless_lifetimes)] // https://github.com/rust-lang/rust/issues/52675 fn project_pin<'a>( - self: Pin<&'a mut Self> + self: Pin<&'a mut Self>, ) -> State, Pin<&'a mut Si>> { unsafe { match &mut Pin::get_unchecked_mut(self).0 { @@ -59,7 +59,7 @@ where Waiting(f) => try_ready!(f.try_poll(lw)), Closed => panic!("poll_ready called after eof"), }; - Pin::set(self.as_mut(), FlattenSink(Ready(resolved_stream))); + Pin::set(&mut self.as_mut(), FlattenSink(Ready(resolved_stream))); if let Ready(resolved_stream) = self.project_pin() { resolved_stream.poll_ready(lw) } else { @@ -99,7 +99,7 @@ where Waiting(_) | Closed => Poll::Ready(Ok(())), }; if res.is_ready() { - Pin::set(self, FlattenSink(Closed)); + Pin::set(&mut self, FlattenSink(Closed)); } res } diff --git a/futures-util/src/try_stream/try_for_each.rs b/futures-util/src/try_stream/try_for_each.rs index 8e26176f80..cb74f50892 100644 --- a/futures-util/src/try_stream/try_for_each.rs +++ b/futures-util/src/try_stream/try_for_each.rs @@ -20,9 +20,10 @@ pub struct TryForEach { impl Unpin for TryForEach {} impl TryForEach -where St: TryStream, - F: FnMut(St::Ok) -> Fut, - Fut: TryFuture, +where + St: TryStream, + F: FnMut(St::Ok) -> Fut, + Fut: TryFuture, { unsafe_pinned!(stream: St); unsafe_unpinned!(f: F); @@ -38,9 +39,10 @@ where St: TryStream, } impl Future for TryForEach - where St: TryStream, - F: FnMut(St::Ok) -> Fut, - Fut: TryFuture, +where + St: TryStream, + F: FnMut(St::Ok) -> Fut, + Fut: TryFuture, { type Output = Result<(), St::Error>; @@ -49,12 +51,12 @@ impl Future for TryForEach if let Some(future) = self.as_mut().future().as_pin_mut() { try_ready!(future.try_poll(lw)); } - Pin::set(self.as_mut().future(), None); + Pin::set(&mut self.as_mut().future(), None); match ready!(self.as_mut().stream().try_poll_next(lw)) { Some(Ok(e)) => { let future = (self.as_mut().f())(e); - Pin::set(self.as_mut().future(), Some(future)); + Pin::set(&mut self.as_mut().future(), Some(future)); } Some(Err(e)) => return Poll::Ready(Err(e)), None => return Poll::Ready(Ok(())),