|
1 |
| -#![feature(async_await)] |
| 1 | +#![feature(async_await, never_type)] |
2 | 2 |
|
3 | 3 | use std::{future::Future, pin::Pin, task::Poll, ptr};
|
4 | 4 | use std::task::{Waker, RawWaker, RawWakerVTable, Context};
|
@@ -40,38 +40,42 @@ async fn includes_never(crash: bool, x: u32) -> u32 {
|
40 | 40 | result
|
41 | 41 | }
|
42 | 42 |
|
43 |
| -fn raw_waker_clone(_this: *const ()) -> RawWaker { |
44 |
| - panic!("unimplemented"); |
| 43 | +async fn partial_init(x: u32) -> u32 { |
| 44 | + #[allow(unreachable_code)] |
| 45 | + let _x: (String, !) = (String::new(), return async { x + x }.await); |
45 | 46 | }
|
46 |
| -fn raw_waker_wake(_this: *const ()) { |
47 |
| - panic!("unimplemented"); |
48 |
| -} |
49 |
| -fn raw_waker_wake_by_ref(_this: *const ()) { |
50 |
| - panic!("unimplemented"); |
51 |
| -} |
52 |
| -fn raw_waker_drop(_this: *const ()) {} |
53 | 47 |
|
54 |
| -static RAW_WAKER: RawWakerVTable = RawWakerVTable::new( |
55 |
| - raw_waker_clone, |
56 |
| - raw_waker_wake, |
57 |
| - raw_waker_wake_by_ref, |
58 |
| - raw_waker_drop, |
59 |
| -); |
| 48 | +fn run_fut(mut fut: impl Future<Output=u32>, output: u32) { |
| 49 | + fn raw_waker_clone(_this: *const ()) -> RawWaker { |
| 50 | + panic!("unimplemented"); |
| 51 | + } |
| 52 | + fn raw_waker_wake(_this: *const ()) { |
| 53 | + panic!("unimplemented"); |
| 54 | + } |
| 55 | + fn raw_waker_wake_by_ref(_this: *const ()) { |
| 56 | + panic!("unimplemented"); |
| 57 | + } |
| 58 | + fn raw_waker_drop(_this: *const ()) {} |
60 | 59 |
|
61 |
| -fn main() { |
62 |
| - let x = 5; |
63 |
| - let mut fut = foo(&x, 7); |
64 |
| - let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) }; |
65 |
| - let mut context = Context::from_waker(&waker); |
66 |
| - assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31)); |
| 60 | + static RAW_WAKER: RawWakerVTable = RawWakerVTable::new( |
| 61 | + raw_waker_clone, |
| 62 | + raw_waker_wake, |
| 63 | + raw_waker_wake_by_ref, |
| 64 | + raw_waker_drop, |
| 65 | + ); |
67 | 66 |
|
68 |
| - let mut fut = build_aggregate(1, 2, 3, 4); |
69 | 67 | let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
|
70 | 68 | let mut context = Context::from_waker(&waker);
|
71 |
| - assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(10)); |
| 69 | + assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(output)); |
| 70 | +} |
72 | 71 |
|
73 |
| - let mut fut = includes_never(false, 4); |
74 |
| - let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) }; |
75 |
| - let mut context = Context::from_waker(&waker); |
76 |
| - assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(16)); |
| 72 | +fn main() { |
| 73 | + let x = 5; |
| 74 | + run_fut(foo(&x, 7), 31); |
| 75 | + |
| 76 | + run_fut(build_aggregate(1, 2, 3, 4), 10); |
| 77 | + |
| 78 | + run_fut(includes_never(false, 4), 16); |
| 79 | + |
| 80 | + run_fut(partial_init(4), 8); |
77 | 81 | }
|
0 commit comments