]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/issue-40003.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / issues / issue-40003.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-pass
12 fn main() {
13 if false { test(); }
14 }
15
16 fn test() {
17 let rx = Err::<Vec<usize>, u32>(1).into_future();
18
19 rx.map(|l: Vec<usize>| stream::iter(l.into_iter().map(|i| Ok(i))))
20 .flatten_stream()
21 .chunks(50)
22 .buffer_unordered(5);
23 }
24
25 use future::{Future, IntoFuture};
26 mod future {
27 use std::result;
28
29 use {stream, Stream};
30
31 pub trait Future {
32 type Item;
33 type Error;
34
35 fn map<F, U>(self, _: F) -> Map<Self, F>
36 where F: FnOnce(Self::Item) -> U,
37 Self: Sized,
38 {
39 panic!()
40 }
41
42 fn flatten_stream(self) -> FlattenStream<Self>
43 where <Self as Future>::Item: stream::Stream<Error=Self::Error>,
44 Self: Sized
45 {
46 panic!()
47 }
48 }
49
50 pub trait IntoFuture {
51 type Future: Future<Item=Self::Item, Error=Self::Error>;
52 type Item;
53 type Error;
54 fn into_future(self) -> Self::Future;
55 }
56
57 impl<F: Future> IntoFuture for F {
58 type Future = F;
59 type Item = F::Item;
60 type Error = F::Error;
61
62 fn into_future(self) -> F {
63 panic!()
64 }
65 }
66
67 impl<T, E> IntoFuture for result::Result<T, E> {
68 type Future = FutureResult<T, E>;
69 type Item = T;
70 type Error = E;
71
72 fn into_future(self) -> FutureResult<T, E> {
73 panic!()
74 }
75 }
76
77 pub struct Map<A, F> {
78 _a: (A, F),
79 }
80
81 impl<U, A, F> Future for Map<A, F>
82 where A: Future,
83 F: FnOnce(A::Item) -> U,
84 {
85 type Item = U;
86 type Error = A::Error;
87 }
88
89 pub struct FlattenStream<F> {
90 _f: F,
91 }
92
93 impl<F> Stream for FlattenStream<F>
94 where F: Future,
95 <F as Future>::Item: Stream<Error=F::Error>,
96 {
97 type Item = <F::Item as Stream>::Item;
98 type Error = <F::Item as Stream>::Error;
99 }
100
101 pub struct FutureResult<T, E> {
102 _inner: (T, E),
103 }
104
105 impl<T, E> Future for FutureResult<T, E> {
106 type Item = T;
107 type Error = E;
108 }
109 }
110
111 mod stream {
112 use IntoFuture;
113
114 pub trait Stream {
115 type Item;
116 type Error;
117
118 fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
119 where Self::Item: IntoFuture<Error = <Self as Stream>::Error>,
120 Self: Sized
121 {
122 new(self, amt)
123 }
124
125 fn chunks(self, _capacity: usize) -> Chunks<Self>
126 where Self: Sized
127 {
128 panic!()
129 }
130 }
131
132 pub struct IterStream<I> {
133 _iter: I,
134 }
135
136 pub fn iter<J, T, E>(_: J) -> IterStream<J::IntoIter>
137 where J: IntoIterator<Item=Result<T, E>>,
138 {
139 panic!()
140 }
141
142 impl<I, T, E> Stream for IterStream<I>
143 where I: Iterator<Item=Result<T, E>>,
144 {
145 type Item = T;
146 type Error = E;
147 }
148
149 pub struct Chunks<S> {
150 _stream: S
151 }
152
153 impl<S> Stream for Chunks<S>
154 where S: Stream
155 {
156 type Item = Result<Vec<<S as Stream>::Item>, u32>;
157 type Error = <S as Stream>::Error;
158 }
159
160 pub struct BufferUnordered<S> {
161 _stream: S,
162 }
163
164 enum Slot<T> {
165 Next(usize),
166 _Data { _a: T },
167 }
168
169 fn new<S>(_s: S, _amt: usize) -> BufferUnordered<S>
170 where S: Stream,
171 S::Item: IntoFuture<Error=<S as Stream>::Error>,
172 {
173 (0..0).map(|_| {
174 Slot::Next::<<S::Item as IntoFuture>::Future>(1)
175 }).collect::<Vec<_>>();
176 panic!()
177 }
178
179 impl<S> Stream for BufferUnordered<S>
180 where S: Stream,
181 S::Item: IntoFuture<Error=<S as Stream>::Error>,
182 {
183 type Item = <S::Item as IntoFuture>::Item;
184 type Error = <S as Stream>::Error;
185 }
186 }
187 use stream::Stream;