]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/union/union-drop-assign.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / union / union-drop-assign.rs
CommitLineData
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
9struct S;
10
11union U {
12 a: S
13}
14
15impl Drop for S {
16 fn drop(&mut self) {
17 unsafe { CHECK += 10; }
18 }
19}
20
21impl Drop for U {
22 fn drop(&mut self) {
23 unsafe { CHECK += 1; }
24 }
25}
26
27static mut CHECK: u8 = 0;
28
29fn 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}