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
poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>13 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
14 Poll::Ready(())
15 }
16 }
17
18 impl Drop for Sleep {
drop(&mut self)19 fn drop(&mut self) {}
20 }
21
sleep() -> Sleep22 fn sleep() -> Sleep {
23 Sleep(std::marker::PhantomPinned)
24 }
25
26
27 struct MyFuture {
28 sleep: Sleep,
29 }
30
31 impl MyFuture {
new() -> Self32 fn new() -> Self {
33 Self {
34 sleep: sleep(),
35 }
36 }
37 }
38
39 impl Future for MyFuture {
40 type Output = ();
41
poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>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
main()48 fn main() {}
49