Skip to content

Commit b26e27c

Browse files
Add test for generator sizes with resume arguments
1 parent 818934b commit b26e27c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![feature(generators)]
2+
3+
// run-pass
4+
5+
use std::mem::size_of_val;
6+
7+
fn main() {
8+
// Generator taking a `Copy`able resume arg.
9+
let gen_copy = |mut x: usize| {
10+
loop {
11+
drop(x);
12+
x = yield;
13+
}
14+
};
15+
16+
// Generator taking a non-`Copy` resume arg.
17+
let gen_move = |mut x: Box<usize>| {
18+
loop {
19+
drop(x);
20+
x = yield;
21+
}
22+
};
23+
24+
// Neither of these generators have the resume arg live across the `yield`, so they should be
25+
// 4 Bytes in size (only storing the discriminant)
26+
assert_eq!(size_of_val(&gen_copy), 4);
27+
assert_eq!(size_of_val(&gen_move), 4);
28+
}

0 commit comments

Comments
 (0)