]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dyn-star/dispatch-on-pin-mut.rs
Auto merge of #106301 - notriddle:notriddle/dir-entry, r=GuillaumeGomez
[rust.git] / src / test / ui / dyn-star / dispatch-on-pin-mut.rs
1 // run-pass
2 // edition:2021
3 // check-run-results
4
5 #![feature(dyn_star)]
6 //~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
7
8 use std::future::Future;
9
10 async fn foo(f: dyn* Future<Output = i32>) {
11     println!("value: {}", f.await);
12 }
13
14 async fn async_main() {
15     foo(Box::pin(async { 1 })).await
16 }
17
18 // ------------------------------------------------------------------------- //
19 // Implementation Details Below...
20
21 use std::pin::Pin;
22 use std::task::*;
23
24 pub fn noop_waker() -> Waker {
25     let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
26
27     // SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
28     unsafe { Waker::from_raw(raw) }
29 }
30
31 const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
32
33 unsafe fn noop_clone(_p: *const ()) -> RawWaker {
34     RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
35 }
36
37 unsafe fn noop(_p: *const ()) {}
38
39 fn main() {
40     let mut fut = async_main();
41
42     // Poll loop, just to test the future...
43     let waker = noop_waker();
44     let ctx = &mut Context::from_waker(&waker);
45
46     loop {
47         match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
48             Poll::Pending => {}
49             Poll::Ready(()) => break,
50         }
51     }
52 }