fix dynamic drop for unions

Moving out of a union is now treated like moving out of its parent type.

Fixes #36246
This commit is contained in:
Ariel Ben-Yehuda 2016-09-08 20:12:53 +03:00 committed by Ariel Ben-Yehuda
parent 7b25e88602
commit eeedc144be
3 changed files with 60 additions and 23 deletions

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
#![feature(untagged_unions)]
use std::cell::{Cell, RefCell};
use std::panic;
@ -111,6 +111,20 @@ fn assignment1(a: &Allocator, c0: bool) {
_v = _w;
}
#[allow(unions_with_drop_fields)]
union Boxy<T> {
a: T,
b: T,
}
fn union1(a: &Allocator) {
unsafe {
let mut u = Boxy { a: a.alloc() };
u.b = a.alloc();
drop(u.a);
}
}
fn run_test<F>(mut f: F)
where F: FnMut(&Allocator)
{
@ -136,6 +150,13 @@ fn run_test<F>(mut f: F)
}
}
fn run_test_nopanic<F>(mut f: F)
where F: FnMut(&Allocator)
{
let first_alloc = Allocator::new(usize::MAX);
f(&first_alloc);
}
fn main() {
run_test(|a| dynamic_init(a, false));
run_test(|a| dynamic_init(a, true));
@ -149,4 +170,6 @@ fn main() {
run_test(|a| assignment1(a, false));
run_test(|a| assignment1(a, true));
run_test_nopanic(|a| union1(a));
}