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