]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/rfc-2008-non-exhaustive/structs.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / compile-fail / rfc-2008-non-exhaustive / structs.rs
1 // Copyright 2012 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.
4 //
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.
10
11 // aux-build:structs.rs
12 extern crate structs;
13
14 use structs::{NormalStruct, UnitStruct, TupleStruct, FunctionalRecord};
15
16 fn main() {
17 let fr = FunctionalRecord {
18 //~^ ERROR cannot create non-exhaustive struct
19 first_field: 1920,
20 second_field: 1080,
21 ..FunctionalRecord::default()
22 };
23
24 let ns = NormalStruct { first_field: 640, second_field: 480 };
25 //~^ ERROR cannot create non-exhaustive struct
26
27 let NormalStruct { first_field, second_field } = ns;
28 //~^ ERROR `..` required with struct marked as non-exhaustive
29
30 let ts = TupleStruct(640, 480);
31 //~^ ERROR expected function, found struct `TupleStruct` [E0423]
32
33 let ts_explicit = structs::TupleStruct(640, 480);
34 //~^ ERROR tuple struct `TupleStruct` is private [E0603]
35
36 let TupleStruct { 0: first_field, 1: second_field } = ts;
37 //~^ ERROR `..` required with struct marked as non-exhaustive
38
39 let us = UnitStruct;
40 //~^ ERROR expected value, found struct `UnitStruct` [E0423]
41
42 let us_explicit = structs::UnitStruct;
43 //~^ ERROR unit struct `UnitStruct` is private [E0603]
44
45 let UnitStruct { } = us;
46 //~^ ERROR `..` required with struct marked as non-exhaustive
47 }