1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(untagged_unions)]
29 fn generic_noncopy<T: Default>() {
30 let mut u3 = U3 { a: T::default() };
31 u3.a = T::default(); //~ ERROR assignment to non-`Copy` union field is unsafe
34 fn generic_copy<T: Copy + Default>() {
35 let mut u3 = U3 { a: T::default() };
36 u3.a = T::default(); // OK
37 let mut u4 = U4 { a: T::default() };
38 u4.a = T::default(); // OK
42 let mut u1 = U1 { a: 10 }; // OK
43 let a = u1.a; //~ ERROR access to union field is unsafe
45 let U1 { a } = u1; //~ ERROR access to union field is unsafe
46 if let U1 { a: 12 } = u1 {} //~ ERROR access to union field is unsafe
47 // let U1 { .. } = u1; // OK
49 let mut u2 = U2 { a: String::from("old") }; // OK
50 u2.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field is unsafe
51 let mut u3 = U3 { a: 0 }; // OK
53 let mut u3 = U3 { a: String::from("old") }; // OK
54 u3.a = String::from("new"); //~ ERROR assignment to non-`Copy` union field is unsafe