diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index 00d306241f..24e4de95eb 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -33,11 +33,11 @@ impl Fanout { } /// Get a pinned mutable reference to the inner sinks. - pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut Si1>, Pin<&mut Si2>) - where Si1: Unpin, Si2: Unpin, - { - let Self { sink1, sink2 } = self.get_mut(); - (Pin::new(sink1), Pin::new(sink2)) + pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut Si1>, Pin<&mut Si2>) { + unsafe { + let Self { sink1, sink2 } = self.get_unchecked_mut(); + (Pin::new_unchecked(sink1), Pin::new_unchecked(sink2)) + } } /// Consumes this combinator, returning the underlying sinks. diff --git a/futures-util/src/stream/into_future.rs b/futures-util/src/stream/into_future.rs index 556e388f83..dce4b40209 100644 --- a/futures-util/src/stream/into_future.rs +++ b/futures-util/src/stream/into_future.rs @@ -3,6 +3,7 @@ use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; +use pin_utils::unsafe_pinned; /// Future for the [`into_future`](super::StreamExt::into_future) method. #[derive(Debug)] @@ -14,6 +15,8 @@ pub struct StreamFuture { impl Unpin for StreamFuture {} impl StreamFuture { + unsafe_pinned!(stream: Option); + pub(super) fn new(stream: St) -> StreamFuture { StreamFuture { stream: Some(stream) } } @@ -54,7 +57,7 @@ impl StreamFuture { /// in order to return it to the caller of `Future::poll` if the stream yielded /// an element. pub fn get_pin_mut(self: Pin<&mut Self>) -> Option> { - Pin::new(&mut self.get_mut().stream).as_pin_mut() + self.stream().as_pin_mut() } /// Consumes this combinator, returning the underlying stream. diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index e40d3f826e..b5fb8133b2 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -56,11 +56,11 @@ impl Select { /// /// Note that care must be taken to avoid tampering with the state of the /// stream which may otherwise confuse this combinator. - pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) - where St1: Unpin, St2: Unpin, - { - let Self { stream1, stream2, .. } = self.get_mut(); - (Pin::new(stream1.get_mut()), Pin::new(stream2.get_mut())) + pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) { + unsafe { + let Self { stream1, stream2, .. } = self.get_unchecked_mut(); + (Pin::new_unchecked(stream1).get_pin_mut(), Pin::new_unchecked(stream2).get_pin_mut()) + } } /// Consumes this combinator, returning the underlying streams. diff --git a/futures-util/src/stream/zip.rs b/futures-util/src/stream/zip.rs index 83b4a0a78a..c8d7f3df0b 100644 --- a/futures-util/src/stream/zip.rs +++ b/futures-util/src/stream/zip.rs @@ -58,11 +58,11 @@ impl Zip { /// /// Note that care must be taken to avoid tampering with the state of the /// stream which may otherwise confuse this combinator. - pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) - where St1: Unpin, St2: Unpin, - { - let Self { stream1, stream2, .. } = self.get_mut(); - (Pin::new(stream1.get_mut()), Pin::new(stream2.get_mut())) + pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) { + unsafe { + let Self { stream1, stream2, .. } = self.get_unchecked_mut(); + (Pin::new_unchecked(stream1).get_pin_mut(), Pin::new_unchecked(stream2).get_pin_mut()) + } } /// Consumes this combinator, returning the underlying streams.