]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2008-non-exhaustive/struct.rs
Auto merge of #103894 - mati865:gnullvm-libunwind-changes, r=thomcc
[rust.git] / src / test / ui / rfc-2008-non-exhaustive / struct.rs
1 // aux-build:structs.rs
2 extern crate structs;
3
4 use structs::{NormalStruct, UnitStruct, TupleStruct, FunctionalRecord};
5
6 fn main() {
7     let fr = FunctionalRecord {
8     //~^ ERROR cannot create non-exhaustive struct
9         first_field: 1920,
10         second_field: 1080,
11         ..FunctionalRecord::default()
12     };
13
14     let ns = NormalStruct { first_field: 640, second_field: 480 };
15     //~^ ERROR cannot create non-exhaustive struct
16
17     let NormalStruct { first_field, second_field } = ns;
18     //~^ ERROR `..` required with struct marked as non-exhaustive
19
20     let ts = TupleStruct(640, 480);
21     //~^ ERROR cannot initialize a tuple struct which contains private fields [E0423]
22
23     let ts_explicit = structs::TupleStruct(640, 480);
24     //~^ ERROR tuple struct constructor `TupleStruct` is private [E0603]
25
26     let TupleStruct { 0: first_field, 1: second_field } = ts;
27     //~^ ERROR `..` required with struct marked as non-exhaustive
28
29     let us = UnitStruct;
30     //~^ ERROR expected value, found struct `UnitStruct` [E0423]
31
32     let us_explicit = structs::UnitStruct;
33     //~^ ERROR unit struct `UnitStruct` is private [E0603]
34
35     let UnitStruct { } = us;
36     //~^ ERROR `..` required with struct marked as non-exhaustive
37 }
38
39 // Everything below this is expected to compile successfully.
40
41 // We only test matching here as we cannot create non-exhaustive
42 // structs from another crate. ie. they'll never pass in run-pass tests.
43 fn match_structs(ns: NormalStruct, ts: TupleStruct, us: UnitStruct) {
44     let NormalStruct { first_field, second_field, .. } = ns;
45
46     let TupleStruct { 0: first, 1: second, .. } = ts;
47
48     let UnitStruct { .. } = us;
49 }