1 #![feature(untagged_unions)]
19 fn generic_noncopy<T: Default>() {
20 let mut u3 = U3 { a: T::default() };
21 u3.a = T::default(); //~ ERROR assignment to non-`Copy` union field is unsafe
24 fn generic_copy<T: Copy + Default>() {
25 let mut u3 = U3 { a: T::default() };
26 u3.a = T::default(); // OK
27 let mut u4 = U4 { a: T::default() };
28 u4.a = T::default(); // OK
32 let mut u1 = U1 { a: 10 }; // OK
33 let a = u1.a; //~ ERROR access to union field is unsafe
35 let U1 { a } = u1; //~ ERROR access to union field is unsafe
36 if let U1 { a: 12 } = u1 {} //~ ERROR access to union field is unsafe
37 // let U1 { .. } = u1; // OK
39 let mut u2 = U2 { a: String::from("old") }; // OK
40 u2.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field is unsafe
41 let mut u3 = U3 { a: 0 }; // OK
43 let mut u3 = U3 { a: String::from("old") }; // OK
44 u3.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field is unsafe