]> git.lizzy.rs Git - rust.git/blob - src/test/ui/union/union-fields-2.rs
Merge commit '03f01bbe901d60b71cf2c5ec766aef5e532ab79d' into update_cg_clif-2020...
[rust.git] / src / test / ui / union / union-fields-2.rs
1 union U {
2     a: u8,
3     b: u16,
4 }
5
6 fn main() {
7     let u = U {}; //~ ERROR union expressions should have exactly one field
8     let u = U { a: 0 }; // OK
9     let u = U { a: 0, b: 1 }; //~ ERROR union expressions should have exactly one field
10     let u = U { a: 0, b: 1, c: 2 }; //~ ERROR union expressions should have exactly one field
11                                     //~^ ERROR union `U` has no field named `c`
12     let u = U { ..u }; //~ ERROR union expressions should have exactly one field
13                        //~^ ERROR functional record update syntax requires a struct
14
15     let U {} = u; //~ ERROR union patterns should have exactly one field
16     let U { a } = u; // OK
17     let U { a, b } = u; //~ ERROR union patterns should have exactly one field
18     let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
19                            //~^ ERROR union `U` does not have a field named `c`
20     let U { .. } = u; //~ ERROR union patterns should have exactly one field
21                       //~^ ERROR `..` cannot be used in union patterns
22     let U { a, .. } = u; //~ ERROR `..` cannot be used in union patterns
23 }