Skip to content

Commit c8116ec

Browse files
stream: work around the rustc bug in StreamExt::collect (#7754)
1 parent 5471a58 commit c8116ec

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

tokio-stream/src/stream_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ pub trait StreamExt: Stream {
916916
/// assert_eq!(Err("no"), values);
917917
/// # }
918918
/// ```
919-
fn collect<T>(self) -> Collect<Self, T>
919+
fn collect<T>(self) -> Collect<Self, T, T::InternalCollection>
920920
where
921921
T: FromStream<Self::Item>,
922922
Self: Sized,

tokio-stream/src/stream_ext/collect.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::Stream;
22

33
use core::future::Future;
4-
use core::marker::PhantomPinned;
4+
use core::marker::{PhantomData, PhantomPinned};
55
use core::mem;
66
use core::pin::Pin;
77
use core::task::{ready, Context, Poll};
@@ -12,14 +12,12 @@ pin_project! {
1212
/// Future returned by the [`collect`](super::StreamExt::collect) method.
1313
#[must_use = "futures do nothing unless you `.await` or poll them"]
1414
#[derive(Debug)]
15-
pub struct Collect<T, U>
16-
where
17-
T: Stream,
18-
U: FromStream<T::Item>,
15+
pub struct Collect<T, U, C>
1916
{
2017
#[pin]
2118
stream: T,
22-
collection: U::InternalCollection,
19+
collection: C,
20+
_output: PhantomData<U>,
2321
// Make this future `!Unpin` for compatibility with async trait methods.
2422
#[pin]
2523
_pin: PhantomPinned,
@@ -38,24 +36,25 @@ pin_project! {
3836
/// enhancements to the Rust language.
3937
pub trait FromStream<T>: sealed::FromStreamPriv<T> {}
4038

41-
impl<T, U> Collect<T, U>
39+
impl<T, U> Collect<T, U, U::InternalCollection>
4240
where
4341
T: Stream,
4442
U: FromStream<T::Item>,
4543
{
46-
pub(super) fn new(stream: T) -> Collect<T, U> {
44+
pub(super) fn new(stream: T) -> Collect<T, U, U::InternalCollection> {
4745
let (lower, upper) = stream.size_hint();
4846
let collection = U::initialize(sealed::Internal, lower, upper);
4947

5048
Collect {
5149
stream,
5250
collection,
51+
_output: PhantomData,
5352
_pin: PhantomPinned,
5453
}
5554
}
5655
}
5756

58-
impl<T, U> Future for Collect<T, U>
57+
impl<T, U> Future for Collect<T, U, U::InternalCollection>
5958
where
6059
T: Stream,
6160
U: FromStream<T::Item>,

0 commit comments

Comments
 (0)