@@ -11,9 +11,21 @@ use core::mem::{self, ManuallyDrop};
1111use core:: pin:: { pin, Pin } ;
1212use core:: task:: { Context , Poll , Waker } ;
1313
14- async fn test_async_drop < T > ( x : T ) {
14+ async fn test_async_drop < T > ( x : T , _size : usize ) {
1515 let mut x = mem:: MaybeUninit :: new ( x) ;
1616 let dtor = pin ! ( unsafe { async_drop_in_place( x. as_mut_ptr( ) ) } ) ;
17+
18+ // FIXME(zetanumbers): This check fully depends on the layout of
19+ // the coroutine state, since async destructor combinators are just
20+ // async functions.
21+ #[ cfg( target_pointer_width = "64" ) ]
22+ assert_eq ! (
23+ mem:: size_of_val( & * dtor) ,
24+ _size,
25+ "sizes did not match for async destructor of type {}" ,
26+ core:: any:: type_name:: <T >( ) ,
27+ ) ;
28+
1729 test_idempotency ( dtor) . await ;
1830}
1931
@@ -34,49 +46,58 @@ fn main() {
3446
3547 let i = 13 ;
3648 let fut = pin ! ( async {
37- test_async_drop( Int ( 0 ) ) . await ;
38- test_async_drop( AsyncInt ( 0 ) ) . await ;
39- test_async_drop( [ AsyncInt ( 1 ) , AsyncInt ( 2 ) ] ) . await ;
40- test_async_drop( ( AsyncInt ( 3 ) , AsyncInt ( 4 ) ) ) . await ;
41- test_async_drop( 5 ) . await ;
49+ test_async_drop( Int ( 0 ) , 16 ) . await ;
50+ test_async_drop( AsyncInt ( 0 ) , 104 ) . await ;
51+ test_async_drop( [ AsyncInt ( 1 ) , AsyncInt ( 2 ) ] , 152 ) . await ;
52+ test_async_drop( ( AsyncInt ( 3 ) , AsyncInt ( 4 ) ) , 488 ) . await ;
53+ test_async_drop( 5 , 0 ) . await ;
4254 let j = 42 ;
43- test_async_drop( & i) . await ;
44- test_async_drop( & j) . await ;
45- test_async_drop( AsyncStruct { b: AsyncInt ( 8 ) , a: AsyncInt ( 7 ) , i: 6 } ) . await ;
46- test_async_drop( ManuallyDrop :: new( AsyncInt ( 9 ) ) ) . await ;
55+ test_async_drop( & i, 0 ) . await ;
56+ test_async_drop( & j, 0 ) . await ;
57+ test_async_drop( AsyncStruct { b: AsyncInt ( 8 ) , a: AsyncInt ( 7 ) , i: 6 } , 1688 ) . await ;
58+ test_async_drop( ManuallyDrop :: new( AsyncInt ( 9 ) ) , 0 ) . await ;
4759
4860 let foo = AsyncInt ( 10 ) ;
49- test_async_drop( AsyncReference { foo: & foo } ) . await ;
61+ test_async_drop( AsyncReference { foo: & foo } , 104 ) . await ;
5062
5163 let foo = AsyncInt ( 11 ) ;
52- test_async_drop( || {
53- black_box( foo) ;
54- let foo = AsyncInt ( 10 ) ;
55- foo
56- } )
64+ test_async_drop(
65+ || {
66+ black_box( foo) ;
67+ let foo = AsyncInt ( 10 ) ;
68+ foo
69+ } ,
70+ 120 ,
71+ )
5772 . await ;
5873
59- test_async_drop( AsyncEnum :: A ( AsyncInt ( 12 ) ) ) . await ;
60- test_async_drop( AsyncEnum :: B ( SyncInt ( 13 ) ) ) . await ;
74+ test_async_drop( AsyncEnum :: A ( AsyncInt ( 12 ) ) , 792 ) . await ;
75+ test_async_drop( AsyncEnum :: B ( SyncInt ( 13 ) ) , 792 ) . await ;
6176
62- test_async_drop( SyncInt ( 14 ) ) . await ;
63- test_async_drop( SyncThenAsync { i: 15 , a: AsyncInt ( 16 ) , b: SyncInt ( 17 ) , c: AsyncInt ( 18 ) } )
64- . await ;
77+ test_async_drop( SyncInt ( 14 ) , 72 ) . await ;
78+ test_async_drop(
79+ SyncThenAsync { i: 15 , a: AsyncInt ( 16 ) , b: SyncInt ( 17 ) , c: AsyncInt ( 18 ) } ,
80+ 3512 ,
81+ )
82+ . await ;
6583
6684 let async_drop_fut = pin!( core:: future:: async_drop( AsyncInt ( 19 ) ) ) ;
6785 test_idempotency( async_drop_fut) . await ;
6886
6987 let foo = AsyncInt ( 20 ) ;
70- test_async_drop( async || {
71- black_box( foo) ;
72- let foo = AsyncInt ( 19 ) ;
73- // Await point there, but this is async closure so it's fine
74- black_box( core:: future:: ready( ( ) ) ) . await ;
75- foo
76- } )
88+ test_async_drop(
89+ async || {
90+ black_box( foo) ;
91+ let foo = AsyncInt ( 19 ) ;
92+ // Await point there, but this is async closure so it's fine
93+ black_box( core:: future:: ready( ( ) ) ) . await ;
94+ foo
95+ } ,
96+ 120 ,
97+ )
7798 . await ;
7899
79- test_async_drop( AsyncUnion { signed: 21 } ) . await ;
100+ test_async_drop( AsyncUnion { signed: 21 } , 32 ) . await ;
80101 } ) ;
81102 let res = fut. poll ( & mut cx) ;
82103 assert_eq ! ( res, Poll :: Ready ( ( ) ) ) ;
0 commit comments