]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
0bf4aa26 | 2 | #![allow(unused_assignments)] |
b7449926 XL |
3 | #![allow(unions_with_drop_fields)] |
4 | ||
9e0c209e SL |
5 | // Drop works for union itself. |
6 | ||
7 | #![feature(untagged_unions)] | |
8 | ||
9 | struct S; | |
10 | ||
11 | union U { | |
12 | a: S | |
13 | } | |
14 | ||
15 | impl Drop for S { | |
16 | fn drop(&mut self) { | |
17 | unsafe { CHECK += 10; } | |
18 | } | |
19 | } | |
20 | ||
21 | impl Drop for U { | |
22 | fn drop(&mut self) { | |
23 | unsafe { CHECK += 1; } | |
24 | } | |
25 | } | |
26 | ||
27 | static mut CHECK: u8 = 0; | |
28 | ||
29 | fn main() { | |
30 | unsafe { | |
31 | let mut u = U { a: S }; | |
32 | assert_eq!(CHECK, 0); | |
33 | u = U { a: S }; | |
34 | assert_eq!(CHECK, 1); // union itself is assigned, union is dropped, field is not dropped | |
35 | u.a = S; | |
36 | assert_eq!(CHECK, 11); // union field is assigned, field is dropped | |
37 | } | |
38 | } |