File tree 6 files changed +80
-20
lines changed
src/tools/miri/tests/pass
6 files changed +80
-20
lines changed Original file line number Diff line number Diff line change @@ -1015,8 +1015,8 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
1015
1015
bug ! ( ) ;
1016
1016
} ;
1017
1017
1018
- // We use `* mut Self` here because we only need to emit an ABI-compatible shim body,
1019
- // rather than match the signature exactly.
1018
+ // We use `& mut Self` here because we only need to emit an ABI-compatible shim body,
1019
+ // rather than match the signature exactly (which might take `&self` instead) .
1020
1020
//
1021
1021
// The self type here is a coroutine-closure, not a coroutine, and we never read from
1022
1022
// it because it never has any captures, because this is only true in the Fn/FnMut
@@ -1025,7 +1025,7 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
1025
1025
if receiver_by_ref {
1026
1026
// Triple-check that there's no captures here.
1027
1027
assert_eq ! ( args. as_coroutine_closure( ) . tupled_upvars_ty( ) , tcx. types. unit) ;
1028
- self_ty = Ty :: new_mut_ptr ( tcx, self_ty) ;
1028
+ self_ty = Ty :: new_mut_ref ( tcx, tcx . lifetimes . re_erased , self_ty) ;
1029
1029
}
1030
1030
1031
1031
let poly_sig = args. as_coroutine_closure ( ) . coroutine_closure_sig ( ) . map_bound ( |sig| {
Original file line number Diff line number Diff line change @@ -125,8 +125,12 @@ fn fn_sig_for_fn_abi<'tcx>(
125
125
coroutine_kind = ty:: ClosureKind :: FnOnce ;
126
126
127
127
// Implementations of `FnMut` and `Fn` for coroutine-closures
128
- // still take their receiver by ref.
129
- if receiver_by_ref { Ty :: new_mut_ptr ( tcx, coroutine_ty) } else { coroutine_ty }
128
+ // still take their receiver by (mut) ref.
129
+ if receiver_by_ref {
130
+ Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , coroutine_ty)
131
+ } else {
132
+ coroutine_ty
133
+ }
130
134
} else {
131
135
tcx. closure_env_ty ( coroutine_ty, coroutine_kind, env_region)
132
136
} ;
Original file line number Diff line number Diff line change
1
+ #![ feature( async_closure, noop_waker, async_fn_traits) ]
2
+
3
+ use std:: future:: Future ;
4
+ use std:: pin:: pin;
5
+ use std:: task:: * ;
6
+
7
+ pub fn block_on < T > ( fut : impl Future < Output = T > ) -> T {
8
+ let mut fut = pin ! ( fut) ;
9
+ let ctx = & mut Context :: from_waker ( Waker :: noop ( ) ) ;
10
+
11
+ loop {
12
+ match fut. as_mut ( ) . poll ( ctx) {
13
+ Poll :: Pending => { }
14
+ Poll :: Ready ( t) => break t,
15
+ }
16
+ }
17
+ }
18
+
19
+ async fn call_once ( f : impl async FnOnce ( DropMe ) ) {
20
+ f ( DropMe ( "world" ) ) . await ;
21
+ }
22
+
23
+ #[ derive( Debug ) ]
24
+ struct DropMe ( & ' static str ) ;
25
+
26
+ impl Drop for DropMe {
27
+ fn drop ( & mut self ) {
28
+ println ! ( "{}" , self . 0 ) ;
29
+ }
30
+ }
31
+
32
+ pub fn main ( ) {
33
+ block_on ( async {
34
+ let b = DropMe ( "hello" ) ;
35
+ let async_closure = async move |a : DropMe | {
36
+ println ! ( "{a:?} {b:?}" ) ;
37
+ } ;
38
+ call_once ( async_closure) . await ;
39
+ } ) ;
40
+ }
Original file line number Diff line number Diff line change
1
+ DropMe("world") DropMe("hello")
2
+ world
3
+ hello
Original file line number Diff line number Diff line change 1
1
#![ feature( async_closure, noop_waker, async_fn_traits) ]
2
2
3
3
use std:: future:: Future ;
4
+ use std:: ops:: { AsyncFnMut , AsyncFnOnce } ;
4
5
use std:: pin:: pin;
5
6
use std:: task:: * ;
6
7
@@ -16,25 +17,36 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
16
17
}
17
18
}
18
19
19
- async fn call_once ( f : impl async FnOnce ( DropMe ) ) {
20
- f ( DropMe ( "world" ) ) . await ;
20
+ async fn call_mut ( f : & mut impl AsyncFnMut ( i32 ) ) {
21
+ f ( 0 ) . await ;
21
22
}
22
23
23
- #[ derive( Debug ) ]
24
- struct DropMe ( & ' static str ) ;
24
+ async fn call_once ( f : impl AsyncFnOnce ( i32 ) ) {
25
+ f ( 1 ) . await ;
26
+ }
25
27
26
- impl Drop for DropMe {
27
- fn drop ( & mut self ) {
28
- println ! ( "{}" , self . 0 ) ;
29
- }
28
+ async fn call_normal < F : Future < Output = ( ) > > ( f : & impl Fn ( i32 ) -> F ) {
29
+ f ( 0 ) . await ;
30
+ }
31
+
32
+ async fn call_normal_once < F : Future < Output = ( ) > > ( f : impl FnOnce ( i32 ) -> F ) {
33
+ f ( 1 ) . await ;
30
34
}
31
35
32
36
pub fn main ( ) {
33
37
block_on ( async {
34
- let b = DropMe ( "hello" ) ;
35
- let async_closure = async move |a : DropMe | {
36
- println ! ( "{a:? } {b:? }" ) ;
38
+ let b = 2i32 ;
39
+ let mut async_closure = async move |a : i32 | {
40
+ println ! ( "{a} {b}" ) ;
37
41
} ;
42
+ call_mut ( & mut async_closure) . await ;
38
43
call_once ( async_closure) . await ;
44
+
45
+ // No-capture closures implement `Fn`.
46
+ let async_closure = async move |a : i32 | {
47
+ println ! ( "{a}" ) ;
48
+ } ;
49
+ call_normal ( & async_closure) . await ;
50
+ call_normal_once ( async_closure) . await ;
39
51
} ) ;
40
- }
52
+ }
Original file line number Diff line number Diff line change 1
- DropMe("world") DropMe("hello")
2
- world
3
- hello
1
+ 0 2
2
+ 1 2
3
+ 0
4
+ 1
You can’t perform that action at this time.
0 commit comments