Skip to content

Commit d5294a5

Browse files
committed
test generator that yields during initialization of struct with uninhabited field
1 parent 1766d1b commit d5294a5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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)