create a drop ladder for an array if any value is moved out

This commit is contained in:
Mikhail Modin 2017-11-28 15:48:23 +03:00
parent 8bcbf91a86
commit 7be2fd853a
5 changed files with 87 additions and 9 deletions

View file

@ -10,7 +10,7 @@
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait, untagged_unions)]
#![feature(generators, generator_trait, untagged_unions, slice_patterns, advanced_slice_patterns)]
use std::cell::{Cell, RefCell};
use std::ops::Generator;
@ -195,6 +195,33 @@ fn vec_unreachable(a: &Allocator) {
let _x = vec![a.alloc(), a.alloc(), a.alloc(), return];
}
fn slice_pattern_first(a: &Allocator) {
let[_x, ..] = [a.alloc(), a.alloc(), a.alloc()];
}
fn slice_pattern_middle(a: &Allocator) {
let[_, _x, _] = [a.alloc(), a.alloc(), a.alloc()];
}
fn slice_pattern_two(a: &Allocator) {
let[_x, _, _y, _] = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
}
fn slice_pattern_last(a: &Allocator) {
let[.., _y] = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
}
fn slice_pattern_one_of(a: &Allocator, i: usize) {
let array = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
let _x = match i {
0 => { let [a, ..] = array; a }
1 => { let [_, a, ..] = array; a }
2 => { let [_, _, a, _] = array; a }
3 => { let [_, _, _, a] = array; a }
_ => panic!("unmatched"),
};
}
fn run_test<F>(mut f: F)
where F: FnMut(&Allocator)
{
@ -264,5 +291,14 @@ fn main() {
run_test(|a| mixed_drop_and_nondrop(a));
run_test(|a| slice_pattern_first(a));
run_test(|a| slice_pattern_middle(a));
run_test(|a| slice_pattern_two(a));
run_test(|a| slice_pattern_last(a));
run_test(|a| slice_pattern_one_of(a, 0));
run_test(|a| slice_pattern_one_of(a, 1));
run_test(|a| slice_pattern_one_of(a, 2));
run_test(|a| slice_pattern_one_of(a, 3));
run_test_nopanic(|a| union1(a));
}