File tree 2 files changed +61
-14
lines changed
2 files changed +61
-14
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature(
2
+ async_await,
3
+ await_macro,
4
+ futures_api,
5
+ pin,
6
+ ) ]
7
+
8
+ use std:: { future:: Future , pin:: Pin , task:: Poll } ;
9
+
10
+ // See if we can run a basic `async fn`
11
+ pub async fn foo ( x : & u32 , y : u32 ) -> u32 {
12
+ let y = & y;
13
+ let z = 9 ;
14
+ let z = & z;
15
+ let y = await ! ( async { * y + * z } ) ;
16
+ let a = 10 ;
17
+ let a = & a;
18
+ * x + y + * a
19
+ }
20
+
21
+ fn main ( ) {
22
+ use std:: { sync:: Arc , task:: { Wake , local_waker} } ;
23
+
24
+ struct NoWake ;
25
+ impl Wake for NoWake {
26
+ fn wake ( _arc_self : & Arc < Self > ) {
27
+ panic ! ( ) ;
28
+ }
29
+ }
30
+
31
+ let lw = unsafe { local_waker ( Arc :: new ( NoWake ) ) } ;
32
+ let x = 5 ;
33
+ let mut fut = foo ( & x, 7 ) ;
34
+ assert_eq ! ( unsafe { Pin :: new_unchecked( & mut fut) } . poll( & lw) , Poll :: Ready ( 31 ) ) ;
35
+ }
Original file line number Diff line number Diff line change 13
13
use std:: ops:: { GeneratorState , Generator } ;
14
14
15
15
fn finish < T > ( mut amt : usize , mut t : T ) -> T :: Return
16
- where T : Generator < Yield = ( ) >
16
+ where T : Generator < Yield = usize >
17
17
{
18
18
loop {
19
19
match unsafe { t. resume ( ) } {
20
- GeneratorState :: Yielded ( ( ) ) => amt -= 1 ,
20
+ GeneratorState :: Yielded ( y ) => amt -= y ,
21
21
GeneratorState :: Complete ( ret) => {
22
22
assert_eq ! ( amt, 0 ) ;
23
23
return ret
@@ -28,38 +28,50 @@ fn finish<T>(mut amt: usize, mut t: T) -> T::Return
28
28
}
29
29
30
30
fn main ( ) {
31
- finish ( 1 , || yield ) ;
31
+ finish ( 1 , || yield 1 ) ;
32
32
finish ( 3 , || {
33
33
let mut x = 0 ;
34
- yield ;
34
+ yield 1 ;
35
35
x += 1 ;
36
- yield ;
36
+ yield 1 ;
37
37
x += 1 ;
38
- yield ;
38
+ yield 1 ;
39
39
assert_eq ! ( x, 2 ) ;
40
40
} ) ;
41
- finish ( 8 , || {
42
- for _ in 0 ..8 {
43
- yield ;
41
+ finish ( 7 * 8 / 2 , || {
42
+ for i in 0 ..8 {
43
+ yield i ;
44
44
}
45
45
} ) ;
46
46
finish ( 1 , || {
47
47
if true {
48
- yield ;
48
+ yield 1 ;
49
49
} else {
50
50
}
51
51
} ) ;
52
52
finish ( 1 , || {
53
53
if false {
54
54
} else {
55
- yield ;
55
+ yield 1 ;
56
56
}
57
57
} ) ;
58
58
finish ( 2 , || {
59
- if { yield ; false } {
60
- yield ;
59
+ if { yield 1 ; false } {
60
+ yield 1 ;
61
61
panic ! ( )
62
62
}
63
- yield
63
+ yield 1 ;
64
64
} ) ;
65
+ // also test a self-referential generator
66
+ assert_eq ! (
67
+ finish( 5 , || {
68
+ let mut x = Box :: new( 5 ) ;
69
+ let y = & mut * x;
70
+ * y = 5 ;
71
+ yield * y;
72
+ * y = 10 ;
73
+ * x
74
+ } ) ,
75
+ 10
76
+ ) ;
65
77
}
You can’t perform that action at this time.
0 commit comments