]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/drop-tracking-unresolved-typeck-results.rs
Rollup merge of #106946 - dtolnay:hashlinecolumn, r=m-ou-se
[rust.git] / tests / ui / async-await / drop-tracking-unresolved-typeck-results.rs
1 // compile-flags: -Zdrop-tracking
2 // incremental
3 // edition: 2021
4
5 use std::future::*;
6 use std::marker::PhantomData;
7 use std::pin::Pin;
8 use std::task::*;
9
10 fn send<T: Send>(_: T) {}
11
12 pub trait Stream {
13     type Item;
14
15     fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
16 }
17
18 struct Empty<T>(PhantomData<fn() -> T>);
19
20 impl<T> Stream for Empty<T> {
21     type Item = T;
22
23     fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
24         todo!()
25     }
26 }
27
28 pub trait FnOnce1<A> {
29     type Output;
30     fn call_once(self, arg: A) -> Self::Output;
31 }
32
33 impl<T, A, R> FnOnce1<A> for T
34 where
35     T: FnOnce(A) -> R,
36 {
37     type Output = R;
38     fn call_once(self, arg: A) -> R {
39         self(arg)
40     }
41 }
42
43 pub trait FnMut1<A>: FnOnce1<A> {
44     fn call_mut(&mut self, arg: A) -> Self::Output;
45 }
46
47 impl<T, A, R> FnMut1<A> for T
48 where
49     T: FnMut(A) -> R,
50 {
51     fn call_mut(&mut self, arg: A) -> R {
52         self(arg)
53     }
54 }
55
56 struct Map<St, F>(St, F);
57
58 impl<St, F> Stream for Map<St, F>
59 where
60     St: Stream,
61     F: FnMut1<St::Item>,
62 {
63     type Item = F::Output;
64
65     fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
66         todo!()
67     }
68 }
69
70 struct FuturesOrdered<T: Future>(PhantomData<fn() -> T::Output>);
71
72 pub struct Buffered<St: Stream>(St, FuturesOrdered<St::Item>, usize)
73 where
74     St::Item: Future;
75
76 impl<St> Stream for Buffered<St>
77 where
78     St: Stream,
79     St::Item: Future,
80 {
81     type Item = <St::Item as Future>::Output;
82
83     fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
84         todo!()
85     }
86 }
87
88 struct Next<'a, T: ?Sized>(&'a T);
89
90 impl<St: ?Sized + Stream + Unpin> Future for Next<'_, St> {
91     type Output = Option<St::Item>;
92
93     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
94         todo!()
95     }
96 }
97
98 fn main() {
99     send(async {
100         //~^ ERROR implementation of `FnOnce` is not general enough
101         //~| ERROR implementation of `FnOnce` is not general enough
102         //~| ERROR implementation of `FnOnce` is not general enough
103         //~| ERROR implementation of `FnOnce` is not general enough
104         Next(&Buffered(Map(Empty(PhantomData), ready::<&()>), FuturesOrdered(PhantomData), 0)).await
105     });
106 }