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