fix generator drop caching

Fixes #45328.
This commit is contained in:
Ariel Ben-Yehuda 2017-10-17 15:20:22 +03:00
parent abe7c87eef
commit a151d37401
2 changed files with 50 additions and 9 deletions

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(untagged_unions)]
#![feature(generators, generator_trait, untagged_unions)]
use std::cell::{Cell, RefCell};
use std::ops::Generator;
use std::panic;
use std::usize;
@ -161,6 +162,21 @@ fn vec_simple(a: &Allocator) {
let _x = vec![a.alloc(), a.alloc(), a.alloc(), a.alloc()];
}
fn generator(a: &Allocator, run_count: usize) {
assert!(run_count < 4);
let mut gen = || {
(a.alloc(),
yield a.alloc(),
a.alloc(),
yield a.alloc()
);
};
for _ in 0..run_count {
gen.resume();
}
}
#[allow(unreachable_code)]
fn vec_unreachable(a: &Allocator) {
let _x = vec![a.alloc(), a.alloc(), a.alloc(), return];
@ -228,5 +244,11 @@ fn main() {
run_test(|a| field_assignment(a, false));
run_test(|a| field_assignment(a, true));
// FIXME: fix leaks on panics
run_test_nopanic(|a| generator(a, 0));
run_test_nopanic(|a| generator(a, 1));
run_test_nopanic(|a| generator(a, 2));
run_test_nopanic(|a| generator(a, 3));
run_test_nopanic(|a| union1(a));
}