@@ -11,9 +11,21 @@ use core::mem::{self, ManuallyDrop};
11
11
use core:: pin:: { pin, Pin } ;
12
12
use core:: task:: { Context , Poll , Waker } ;
13
13
14
- async fn test_async_drop < T > ( x : T ) {
14
+ async fn test_async_drop < T > ( x : T , _size : usize ) {
15
15
let mut x = mem:: MaybeUninit :: new ( x) ;
16
16
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
+
17
29
test_idempotency ( dtor) . await ;
18
30
}
19
31
@@ -34,49 +46,58 @@ fn main() {
34
46
35
47
let i = 13 ;
36
48
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 ;
42
54
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 ;
47
59
48
60
let foo = AsyncInt ( 10 ) ;
49
- test_async_drop( AsyncReference { foo: & foo } ) . await ;
61
+ test_async_drop( AsyncReference { foo: & foo } , 104 ) . await ;
50
62
51
63
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
+ )
57
72
. await ;
58
73
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 ;
61
76
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 ;
65
83
66
84
let async_drop_fut = pin!( core:: future:: async_drop( AsyncInt ( 19 ) ) ) ;
67
85
test_idempotency( async_drop_fut) . await ;
68
86
69
87
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
+ )
77
98
. await ;
78
99
79
- test_async_drop( AsyncUnion { signed: 21 } ) . await ;
100
+ test_async_drop( AsyncUnion { signed: 21 } , 32 ) . await ;
80
101
} ) ;
81
102
let res = fut. poll ( & mut cx) ;
82
103
assert_eq ! ( res, Poll :: Ready ( ( ) ) ) ;
0 commit comments