about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-10-17 09:00:11 +0000
committerbors <bors@rust-lang.org>2017-10-17 09:00:11 +0000
commit611f375a862148595d1d7c221870312e572f7d3c (patch)
tree03649c51786f8af262eee00e9b5edde881e44857
parentdb80da1c1a20529054ce6745a6219c2108693fb7 (diff)
parent045916603ed55c95169770ed4423d5da18411335 (diff)
downloadrust-611f375a862148595d1d7c221870312e572f7d3c.tar.gz
rust-611f375a862148595d1d7c221870312e572f7d3c.zip
Auto merge of #45311 - goffrie:issue-40003, r=alexcrichton
Add the test for #40003.

I checked that the test failed to compile on an older nightly (I tried 2017-09-29) and that it compiles against master.

Closes #40003.
-rw-r--r--src/test/run-pass/issue-40003.rs186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-40003.rs b/src/test/run-pass/issue-40003.rs
new file mode 100644
index 00000000000..103a365af0e
--- /dev/null
+++ b/src/test/run-pass/issue-40003.rs
@@ -0,0 +1,186 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    if false { test(); }
+}
+
+fn test() {
+    let rx = Err::<Vec<usize>, u32>(1).into_future();
+
+    rx.map(|l: Vec<usize>| stream::iter(l.into_iter().map(|i| Ok(i))))
+      .flatten_stream()
+      .chunks(50)
+      .buffer_unordered(5);
+}
+
+use future::{Future, IntoFuture};
+mod future {
+    use std::result;
+
+    use {stream, Stream};
+
+    pub trait Future {
+        type Item;
+        type Error;
+
+        fn map<F, U>(self, _: F) -> Map<Self, F>
+            where F: FnOnce(Self::Item) -> U,
+                  Self: Sized,
+        {
+            panic!()
+        }
+
+        fn flatten_stream(self) -> FlattenStream<Self>
+            where <Self as Future>::Item: stream::Stream<Error=Self::Error>,
+                  Self: Sized
+        {
+            panic!()
+        }
+    }
+
+    pub trait IntoFuture {
+        type Future: Future<Item=Self::Item, Error=Self::Error>;
+        type Item;
+        type Error;
+        fn into_future(self) -> Self::Future;
+    }
+
+    impl<F: Future> IntoFuture for F {
+        type Future = F;
+        type Item = F::Item;
+        type Error = F::Error;
+
+        fn into_future(self) -> F {
+            panic!()
+        }
+    }
+
+    impl<T, E> IntoFuture for result::Result<T, E> {
+        type Future = FutureResult<T, E>;
+        type Item = T;
+        type Error = E;
+
+        fn into_future(self) -> FutureResult<T, E> {
+            panic!()
+        }
+    }
+
+    pub struct Map<A, F> {
+        _a: (A, F),
+    }
+
+    impl<U, A, F> Future for Map<A, F>
+        where A: Future,
+              F: FnOnce(A::Item) -> U,
+    {
+        type Item = U;
+        type Error = A::Error;
+    }
+
+    pub struct FlattenStream<F> {
+        _f: F,
+    }
+
+    impl<F> Stream for FlattenStream<F>
+        where F: Future,
+              <F as Future>::Item: Stream<Error=F::Error>,
+    {
+        type Item = <F::Item as Stream>::Item;
+        type Error = <F::Item as Stream>::Error;
+    }
+
+    pub struct FutureResult<T, E> {
+        _inner: (T, E),
+    }
+
+    impl<T, E> Future for FutureResult<T, E> {
+        type Item = T;
+        type Error = E;
+    }
+}
+
+mod stream {
+    use IntoFuture;
+
+    pub trait Stream {
+        type Item;
+        type Error;
+
+        fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
+            where Self::Item: IntoFuture<Error = <Self as Stream>::Error>,
+                  Self: Sized
+        {
+            new(self, amt)
+        }
+
+        fn chunks(self, _capacity: usize) -> Chunks<Self>
+            where Self: Sized
+        {
+            panic!()
+        }
+    }
+
+    pub struct IterStream<I> {
+        _iter: I,
+    }
+
+    pub fn iter<J, T, E>(_: J) -> IterStream<J::IntoIter>
+        where J: IntoIterator<Item=Result<T, E>>,
+    {
+        panic!()
+    }
+
+    impl<I, T, E> Stream for IterStream<I>
+        where I: Iterator<Item=Result<T, E>>,
+    {
+        type Item = T;
+        type Error = E;
+    }
+
+    pub struct Chunks<S> {
+        _stream: S
+    }
+
+    impl<S> Stream for Chunks<S>
+        where S: Stream
+    {
+        type Item = Result<Vec<<S as Stream>::Item>, u32>;
+        type Error = <S as Stream>::Error;
+    }
+
+    pub struct BufferUnordered<S> {
+        _stream: S,
+    }
+
+    enum Slot<T> {
+        Next(usize),
+        _Data { _a: T },
+    }
+
+    fn new<S>(_s: S, _amt: usize) -> BufferUnordered<S>
+        where S: Stream,
+              S::Item: IntoFuture<Error=<S as Stream>::Error>,
+    {
+        (0..0).map(|_| {
+            Slot::Next::<<S::Item as IntoFuture>::Future>(1)
+        }).collect::<Vec<_>>();
+        panic!()
+    }
+
+    impl<S> Stream for BufferUnordered<S>
+        where S: Stream,
+              S::Item: IntoFuture<Error=<S as Stream>::Error>,
+    {
+        type Item = <S::Item as IntoFuture>::Item;
+        type Error = <S as Stream>::Error;
+    }
+}
+use stream::Stream;