1
1
//@revisions: stack tree
2
2
//@compile-flags: -Zmiri-strict-provenance
3
3
//@[tree]compile-flags: -Zmiri-tree-borrows
4
+
5
+ // WARNING: If you would ever want to modify this test,
6
+ // please consider modifying rustc's async drop test at
7
+ // `tests/ui/async-await/async-drop.rs`.
8
+
4
9
#![ feature( async_drop, impl_trait_in_assoc_type, noop_waker, async_closure) ]
5
10
#![ allow( incomplete_features, dead_code) ]
6
11
@@ -11,21 +16,9 @@ use core::mem::{self, ManuallyDrop};
11
16
use core:: pin:: { pin, Pin } ;
12
17
use core:: task:: { Context , Poll , Waker } ;
13
18
14
- async fn test_async_drop < T > ( x : T , _size : usize ) {
19
+ async fn test_async_drop < T > ( x : T ) {
15
20
let mut x = mem:: MaybeUninit :: new ( x) ;
16
21
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
-
29
22
test_idempotency ( dtor) . await ;
30
23
}
31
24
@@ -46,58 +39,49 @@ fn main() {
46
39
47
40
let i = 13 ;
48
41
let fut = pin ! ( async {
49
- test_async_drop( Int ( 0 ) , 0 ) . 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
+ test_async_drop( Int ( 0 ) ) . await ;
43
+ test_async_drop( AsyncInt ( 0 ) ) . await ;
44
+ test_async_drop( [ AsyncInt ( 1 ) , AsyncInt ( 2 ) ] ) . await ;
45
+ test_async_drop( ( AsyncInt ( 3 ) , AsyncInt ( 4 ) ) ) . await ;
46
+ test_async_drop( 5 ) . await ;
54
47
let j = 42 ;
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 ;
48
+ test_async_drop( & i) . await ;
49
+ test_async_drop( & j) . await ;
50
+ test_async_drop( AsyncStruct { b: AsyncInt ( 8 ) , a: AsyncInt ( 7 ) , i: 6 } ) . await ;
51
+ test_async_drop( ManuallyDrop :: new( AsyncInt ( 9 ) ) ) . await ;
59
52
60
53
let foo = AsyncInt ( 10 ) ;
61
- test_async_drop( AsyncReference { foo: & foo } , 104 ) . await ;
54
+ test_async_drop( AsyncReference { foo: & foo } ) . await ;
62
55
63
56
let foo = AsyncInt ( 11 ) ;
64
- test_async_drop(
65
- || {
66
- black_box( foo) ;
67
- let foo = AsyncInt ( 10 ) ;
68
- foo
69
- } ,
70
- 120 ,
71
- )
57
+ test_async_drop( || {
58
+ black_box( foo) ;
59
+ let foo = AsyncInt ( 10 ) ;
60
+ foo
61
+ } )
72
62
. await ;
73
63
74
- test_async_drop( AsyncEnum :: A ( AsyncInt ( 12 ) ) , 680 ) . await ;
75
- test_async_drop( AsyncEnum :: B ( SyncInt ( 13 ) ) , 680 ) . await ;
64
+ test_async_drop( AsyncEnum :: A ( AsyncInt ( 12 ) ) ) . await ;
65
+ test_async_drop( AsyncEnum :: B ( SyncInt ( 13 ) ) ) . await ;
76
66
77
- test_async_drop( SyncInt ( 14 ) , 16 ) . await ;
78
- test_async_drop(
79
- SyncThenAsync { i: 15 , a: AsyncInt ( 16 ) , b: SyncInt ( 17 ) , c: AsyncInt ( 18 ) } ,
80
- 3064 ,
81
- )
82
- . await ;
67
+ test_async_drop( SyncInt ( 14 ) ) . await ;
68
+ test_async_drop( SyncThenAsync { i: 15 , a: AsyncInt ( 16 ) , b: SyncInt ( 17 ) , c: AsyncInt ( 18 ) } )
69
+ . await ;
83
70
84
71
let async_drop_fut = pin!( core:: future:: async_drop( AsyncInt ( 19 ) ) ) ;
85
72
test_idempotency( async_drop_fut) . await ;
86
73
87
74
let foo = AsyncInt ( 20 ) ;
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
- )
75
+ test_async_drop( async || {
76
+ black_box( foo) ;
77
+ let foo = AsyncInt ( 19 ) ;
78
+ // Await point there, but this is async closure so it's fine
79
+ black_box( core:: future:: ready( ( ) ) ) . await ;
80
+ foo
81
+ } )
98
82
. await ;
99
83
100
- test_async_drop( AsyncUnion { signed: 21 } , 32 ) . await ;
84
+ test_async_drop( AsyncUnion { signed: 21 } ) . await ;
101
85
} ) ;
102
86
let res = fut. poll ( & mut cx) ;
103
87
assert_eq ! ( res, Poll :: Ready ( ( ) ) ) ;
0 commit comments