diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2016-09-08 20:12:53 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <arielb1@mail.tau.ac.il> | 2016-09-16 15:08:32 +0300 |
| commit | eeedc144be1f57cda196638d7bf38cf4cd2b9700 (patch) | |
| tree | 2c6ab978b9a728ba63e239f6a460d328f42a9a2b /src/test | |
| parent | 7b25e886028195a4f90c0baa5cc9101ebeceb5a3 (diff) | |
| download | rust-eeedc144be1f57cda196638d7bf38cf4cd2b9700.tar.gz rust-eeedc144be1f57cda196638d7bf38cf4cd2b9700.zip | |
fix dynamic drop for unions
Moving out of a union is now treated like moving out of its parent type. Fixes #36246
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/dynamic-drop.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/run-pass/dynamic-drop.rs b/src/test/run-pass/dynamic-drop.rs index 2b016dfb33e..a2cca206409 100644 --- a/src/test/run-pass/dynamic-drop.rs +++ b/src/test/run-pass/dynamic-drop.rs @@ -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)); } |
