]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-38033.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / ui / issues / issue-38033.rs
1 // run-pass
2 use std::marker;
3 use std::mem;
4
5 fn main() {
6 let workers = (0..0).map(|_| result::<u32, ()>());
7 drop(join_all(workers).poll());
8 }
9
10 trait Future {
11 type Item;
12 type Error;
13
14 fn poll(&mut self) -> Result<Self::Item, Self::Error>;
15 }
16
17 trait IntoFuture {
18 type Future: Future<Item=Self::Item, Error=Self::Error>;
19 type Item;
20 type Error;
21
22 fn into_future(self) -> Self::Future;
23 }
24
25 impl<F: Future> IntoFuture for F {
26 type Future = F;
27 type Item = F::Item;
28 type Error = F::Error;
29
30 fn into_future(self) -> F {
31 self
32 }
33 }
34
35 struct FutureResult<T, E> {
36 _inner: marker::PhantomData<(T, E)>,
37 }
38
39 fn result<T, E>() -> FutureResult<T, E> {
40 loop {}
41 }
42
43 impl<T, E> Future for FutureResult<T, E> {
44 type Item = T;
45 type Error = E;
46
47 fn poll(&mut self) -> Result<T, E> {
48 loop {}
49 }
50 }
51
52 struct JoinAll<I>
53 where I: IntoIterator,
54 I::Item: IntoFuture,
55 {
56 elems: Vec<<I::Item as IntoFuture>::Item>,
57 }
58
59 fn join_all<I>(_: I) -> JoinAll<I>
60 where I: IntoIterator,
61 I::Item: IntoFuture,
62 {
63 JoinAll { elems: vec![] }
64 }
65
66 impl<I> Future for JoinAll<I>
67 where I: IntoIterator,
68 I::Item: IntoFuture,
69 {
70 type Item = Vec<<I::Item as IntoFuture>::Item>;
71 type Error = <I::Item as IntoFuture>::Error;
72
73 fn poll(&mut self) -> Result<Self::Item, Self::Error> {
74 let elems = mem::replace(&mut self.elems, Vec::new());
75 Ok(elems.into_iter().map(|e| {
76 e
77 }).collect::<Vec<_>>())
78 }
79 }