4
4
5
5
// WARNING: If you would ever want to modify this test,
6
6
// please consider modifying rustc's async drop test at
7
- // `tests/ui/async-await/async-drop.rs`.
7
+ // `tests/ui/async-await/async-drop/async-drop-initial .rs`.
8
8
9
9
#![ feature( async_drop, impl_trait_in_assoc_type) ]
10
10
#![ allow( incomplete_features, dead_code) ]
11
11
12
12
// FIXME(zetanumbers): consider AsyncDestruct::async_drop cleanup tests
13
- use core:: future:: { AsyncDrop , Future , async_drop_in_place } ;
13
+ use core:: future:: { async_drop_in_place , AsyncDrop , Future } ;
14
14
use core:: hint:: black_box;
15
15
use core:: mem:: { self , ManuallyDrop } ;
16
- use core:: pin:: { Pin , pin } ;
16
+ use core:: pin:: { pin , Pin } ;
17
17
use core:: task:: { Context , Poll , Waker } ;
18
18
19
19
async fn test_async_drop < T > ( x : T ) {
@@ -68,7 +68,8 @@ fn main() {
68
68
test_async_drop( SyncThenAsync { i: 15 , a: AsyncInt ( 16 ) , b: SyncInt ( 17 ) , c: AsyncInt ( 18 ) } )
69
69
. await ;
70
70
71
- let async_drop_fut = pin!( core:: future:: async_drop( AsyncInt ( 19 ) ) ) ;
71
+ let mut ptr19 = mem:: MaybeUninit :: new( AsyncInt ( 19 ) ) ;
72
+ let async_drop_fut = pin!( unsafe { async_drop_in_place( ptr19. as_mut_ptr( ) ) } ) ;
72
73
test_idempotency( async_drop_fut) . await ;
73
74
74
75
let foo = AsyncInt ( 20 ) ;
@@ -89,13 +90,14 @@ fn main() {
89
90
90
91
struct AsyncInt ( i32 ) ;
91
92
93
+ impl Drop for AsyncInt {
94
+ fn drop ( & mut self ) {
95
+ println ! ( "AsyncInt::drop: {}" , self . 0 ) ;
96
+ }
97
+ }
92
98
impl AsyncDrop for AsyncInt {
93
- type Dropper < ' a > = impl Future < Output = ( ) > ;
94
-
95
- fn async_drop ( self : Pin < & mut Self > ) -> Self :: Dropper < ' _ > {
96
- async move {
97
- println ! ( "AsyncInt::Dropper::poll: {}" , self . 0 ) ;
98
- }
99
+ async fn drop ( self : Pin < & mut Self > ) {
100
+ println ! ( "AsyncInt::async_drop: {}" , self . 0 ) ;
99
101
}
100
102
}
101
103
@@ -124,16 +126,14 @@ struct AsyncReference<'a> {
124
126
foo : & ' a AsyncInt ,
125
127
}
126
128
129
+ impl Drop for AsyncReference < ' _ > {
130
+ fn drop ( & mut self ) {
131
+ println ! ( "AsyncReference::drop: {}" , self . foo. 0 ) ;
132
+ }
133
+ }
127
134
impl AsyncDrop for AsyncReference < ' _ > {
128
- type Dropper < ' a >
129
- = impl Future < Output = ( ) >
130
- where
131
- Self : ' a ;
132
-
133
- fn async_drop ( self : Pin < & mut Self > ) -> Self :: Dropper < ' _ > {
134
- async move {
135
- println ! ( "AsyncReference::Dropper::poll: {}" , self . foo. 0 ) ;
136
- }
135
+ async fn drop ( self : Pin < & mut Self > ) {
136
+ println ! ( "AsyncReference::async_drop: {}" , self . foo. 0 ) ;
137
137
}
138
138
}
139
139
@@ -145,13 +145,14 @@ struct AsyncStruct {
145
145
b : AsyncInt ,
146
146
}
147
147
148
+ impl Drop for AsyncStruct {
149
+ fn drop ( & mut self ) {
150
+ println ! ( "AsyncStruct::drop: {}" , self . i) ;
151
+ }
152
+ }
148
153
impl AsyncDrop for AsyncStruct {
149
- type Dropper < ' a > = impl Future < Output = ( ) > ;
150
-
151
- fn async_drop ( self : Pin < & mut Self > ) -> Self :: Dropper < ' _ > {
152
- async move {
153
- println ! ( "AsyncStruct::Dropper::poll: {}" , self . i) ;
154
- }
154
+ async fn drop ( self : Pin < & mut Self > ) {
155
+ println ! ( "AsyncStruct::async_drop: {}" , self . i) ;
155
156
}
156
157
}
157
158
@@ -160,23 +161,34 @@ enum AsyncEnum {
160
161
B ( SyncInt ) ,
161
162
}
162
163
164
+ impl Drop for AsyncEnum {
165
+ fn drop ( & mut self ) {
166
+ let new_self = match self {
167
+ AsyncEnum :: A ( foo) => {
168
+ println ! ( "AsyncEnum(A)::drop: {}" , foo. 0 ) ;
169
+ AsyncEnum :: B ( SyncInt ( foo. 0 ) )
170
+ }
171
+ AsyncEnum :: B ( foo) => {
172
+ println ! ( "AsyncEnum(B)::drop: {}" , foo. 0 ) ;
173
+ AsyncEnum :: A ( AsyncInt ( foo. 0 ) )
174
+ }
175
+ } ;
176
+ mem:: forget ( mem:: replace ( & mut * self , new_self) ) ;
177
+ }
178
+ }
163
179
impl AsyncDrop for AsyncEnum {
164
- type Dropper < ' a > = impl Future < Output = ( ) > ;
165
-
166
- fn async_drop ( mut self : Pin < & mut Self > ) -> Self :: Dropper < ' _ > {
167
- async move {
168
- let new_self = match & * self {
169
- AsyncEnum :: A ( foo) => {
170
- println ! ( "AsyncEnum(A)::Dropper::poll: {}" , foo. 0 ) ;
171
- AsyncEnum :: B ( SyncInt ( foo. 0 ) )
172
- }
173
- AsyncEnum :: B ( foo) => {
174
- println ! ( "AsyncEnum(B)::Dropper::poll: {}" , foo. 0 ) ;
175
- AsyncEnum :: A ( AsyncInt ( foo. 0 ) )
176
- }
177
- } ;
178
- mem:: forget ( mem:: replace ( & mut * self , new_self) ) ;
179
- }
180
+ async fn drop ( mut self : Pin < & mut Self > ) {
181
+ let new_self = match & * self {
182
+ AsyncEnum :: A ( foo) => {
183
+ println ! ( "AsyncEnum(A)::async_drop: {}" , foo. 0 ) ;
184
+ AsyncEnum :: B ( SyncInt ( foo. 0 ) )
185
+ }
186
+ AsyncEnum :: B ( foo) => {
187
+ println ! ( "AsyncEnum(B)::async_drop: {}" , foo. 0 ) ;
188
+ AsyncEnum :: A ( AsyncInt ( foo. 0 ) )
189
+ }
190
+ } ;
191
+ mem:: forget ( mem:: replace ( & mut * self , new_self) ) ;
180
192
}
181
193
}
182
194
@@ -186,14 +198,19 @@ union AsyncUnion {
186
198
unsigned : u32 ,
187
199
}
188
200
201
+ impl Drop for AsyncUnion {
202
+ fn drop ( & mut self ) {
203
+ println ! (
204
+ "AsyncUnion::drop: {}, {}" ,
205
+ unsafe { self . signed } ,
206
+ unsafe { self . unsigned } ,
207
+ ) ;
208
+ }
209
+ }
189
210
impl AsyncDrop for AsyncUnion {
190
- type Dropper < ' a > = impl Future < Output = ( ) > ;
191
-
192
- fn async_drop ( self : Pin < & mut Self > ) -> Self :: Dropper < ' _ > {
193
- async move {
194
- println ! ( "AsyncUnion::Dropper::poll: {}, {}" , unsafe { self . signed } , unsafe {
195
- self . unsigned
196
- } ) ;
197
- }
211
+ async fn drop ( self : Pin < & mut Self > ) {
212
+ println ! ( "AsyncUnion::async_drop: {}, {}" , unsafe { self . signed } , unsafe {
213
+ self . unsigned
214
+ } ) ;
198
215
}
199
216
}
0 commit comments