]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/pin-needed-to-poll-2.rs
Rollup merge of #106973 - oli-obk:tait_ice_closure_in_impl_header, r=lcnr
[rust.git] / tests / ui / async-await / pin-needed-to-poll-2.rs
1 use std::{
2     future::Future,
3     pin::Pin,
4     marker::Unpin,
5     task::{Context, Poll},
6 };
7
8 struct Sleep(std::marker::PhantomPinned);
9
10 impl Future for Sleep {
11     type Output = ();
12
13     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
14         Poll::Ready(())
15     }
16 }
17
18 impl Drop for Sleep {
19     fn drop(&mut self) {}
20 }
21
22 fn sleep() -> Sleep {
23     Sleep(std::marker::PhantomPinned)
24 }
25
26
27 struct MyFuture {
28     sleep: Sleep,
29 }
30
31 impl MyFuture {
32     fn new() -> Self {
33         Self {
34             sleep: sleep(),
35         }
36     }
37 }
38
39 impl Future for MyFuture {
40     type Output = ();
41
42     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
43         Pin::new(&mut self.sleep).poll(cx)
44         //~^ ERROR `PhantomPinned` cannot be unpinned
45     }
46 }
47
48 fn main() {}