Skip to content

Commit 7b3de39

Browse files
committed
Auto merge of #899 - RalfJung:generators, r=RalfJung
More generator tests Cc @tmandry -- do these look reasonable for checking the new "partial init" case that was discovered?
2 parents b55ae00 + b5ce8f4 commit 7b3de39

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4be067558962c004b638e4c6f162d50f7c0c98b6
1+
5aa3d9a7b5d3a46a7f158e8881146331a6bc9243

tests/run-pass/async-fn.rs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(async_await)]
1+
#![feature(async_await, never_type)]
22

33
use std::{future::Future, pin::Pin, task::Poll, ptr};
44
use std::task::{Waker, RawWaker, RawWakerVTable, Context};
@@ -40,38 +40,42 @@ async fn includes_never(crash: bool, x: u32) -> u32 {
4040
result
4141
}
4242

43-
fn raw_waker_clone(_this: *const ()) -> RawWaker {
44-
panic!("unimplemented");
43+
async fn partial_init(x: u32) -> u32 {
44+
#[allow(unreachable_code)]
45+
let _x: (String, !) = (String::new(), return async { x + x }.await);
4546
}
46-
fn raw_waker_wake(_this: *const ()) {
47-
panic!("unimplemented");
48-
}
49-
fn raw_waker_wake_by_ref(_this: *const ()) {
50-
panic!("unimplemented");
51-
}
52-
fn raw_waker_drop(_this: *const ()) {}
5347

54-
static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
55-
raw_waker_clone,
56-
raw_waker_wake,
57-
raw_waker_wake_by_ref,
58-
raw_waker_drop,
59-
);
48+
fn run_fut(mut fut: impl Future<Output=u32>, output: u32) {
49+
fn raw_waker_clone(_this: *const ()) -> RawWaker {
50+
panic!("unimplemented");
51+
}
52+
fn raw_waker_wake(_this: *const ()) {
53+
panic!("unimplemented");
54+
}
55+
fn raw_waker_wake_by_ref(_this: *const ()) {
56+
panic!("unimplemented");
57+
}
58+
fn raw_waker_drop(_this: *const ()) {}
6059

61-
fn main() {
62-
let x = 5;
63-
let mut fut = foo(&x, 7);
64-
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
65-
let mut context = Context::from_waker(&waker);
66-
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
60+
static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
61+
raw_waker_clone,
62+
raw_waker_wake,
63+
raw_waker_wake_by_ref,
64+
raw_waker_drop,
65+
);
6766

68-
let mut fut = build_aggregate(1, 2, 3, 4);
6967
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
7068
let mut context = Context::from_waker(&waker);
71-
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(10));
69+
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(output));
70+
}
7271

73-
let mut fut = includes_never(false, 4);
74-
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
75-
let mut context = Context::from_waker(&waker);
76-
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(16));
72+
fn main() {
73+
let x = 5;
74+
run_fut(foo(&x, 7), 31);
75+
76+
run_fut(build_aggregate(1, 2, 3, 4), 10);
77+
78+
run_fut(includes_never(false, 4), 16);
79+
80+
run_fut(partial_init(4), 8);
7781
}

tests/run-pass/generator.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(generators, generator_trait)]
1+
#![feature(generators, generator_trait, never_type)]
22

33
use std::ops::{GeneratorState, Generator};
44
use std::pin::Pin;
@@ -26,6 +26,7 @@ fn never() -> Never {
2626

2727
fn main() {
2828
finish(1, || yield 1);
29+
2930
finish(3, || {
3031
let mut x = 0;
3132
yield 1;
@@ -35,30 +36,35 @@ fn main() {
3536
yield 1;
3637
assert_eq!(x, 2);
3738
});
39+
3840
finish(7*8/2, || {
3941
for i in 0..8 {
4042
yield i;
4143
}
4244
});
45+
4346
finish(1, || {
4447
if true {
4548
yield 1;
4649
} else {
4750
}
4851
});
52+
4953
finish(1, || {
5054
if false {
5155
} else {
5256
yield 1;
5357
}
5458
});
59+
5560
finish(2, || {
5661
if { yield 1; false } {
5762
yield 1;
5863
panic!()
5964
}
6065
yield 1;
6166
});
67+
6268
// also test a self-referential generator
6369
assert_eq!(
6470
finish(5, || {
@@ -71,6 +77,7 @@ fn main() {
7177
}),
7278
10
7379
);
80+
7481
let b = true;
7582
finish(1, || {
7683
yield 1;
@@ -80,4 +87,10 @@ fn main() {
8087
yield 2;
8188
drop(x);
8289
});
90+
91+
finish(3, || {
92+
yield 1;
93+
#[allow(unreachable_code)]
94+
let _x: (String, !) = (String::new(), { yield 2; return });
95+
});
8396
}

0 commit comments

Comments
 (0)