]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/privacy5.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / privacy5.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 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
c34b1796 11// aux-build:privacy_tuple_struct.rs
1a4d82fc 12
c34b1796 13extern crate privacy_tuple_struct as other;
1a4d82fc
JJ
14
15mod a {
16 pub struct A(());
17 pub struct B(isize);
18 pub struct C(pub isize, isize);
19 pub struct D(pub isize);
20
21 fn test() {
22 let a = A(());
23 let b = B(2);
24 let c = C(2, 3);
25 let d = D(4);
26
27 let A(()) = a;
28 let A(_) = a;
29 match a { A(()) => {} }
30 match a { A(_) => {} }
31
32 let B(_) = b;
33 let B(_b) = b;
34 match b { B(_) => {} }
35 match b { B(_b) => {} }
36 match b { B(1) => {} B(_) => {} }
37
38 let C(_, _) = c;
39 let C(_a, _) = c;
40 let C(_, _b) = c;
41 let C(_a, _b) = c;
42 match c { C(_, _) => {} }
43 match c { C(_a, _) => {} }
44 match c { C(_, _b) => {} }
45 match c { C(_a, _b) => {} }
46
47 let D(_) = d;
48 let D(_d) = d;
49 match d { D(_) => {} }
50 match d { D(_d) => {} }
51 match d { D(1) => {} D(_) => {} }
52
53 let a2 = A;
54 let b2 = B;
55 let c2 = C;
56 let d2 = D;
57 }
58}
59
60fn this_crate() {
61 let a = a::A(()); //~ ERROR: cannot invoke tuple struct constructor
62 let b = a::B(2); //~ ERROR: cannot invoke tuple struct constructor
63 let c = a::C(2, 3); //~ ERROR: cannot invoke tuple struct constructor
64 let d = a::D(4);
65
54a0048b 66 let a::A(()) = a; //~ ERROR: field `0` of struct `a::A` is private
1a4d82fc 67 let a::A(_) = a;
54a0048b 68 match a { a::A(()) => {} } //~ ERROR: field `0` of struct `a::A` is private
1a4d82fc
JJ
69 match a { a::A(_) => {} }
70
71 let a::B(_) = b;
54a0048b 72 let a::B(_b) = b; //~ ERROR: field `0` of struct `a::B` is private
1a4d82fc 73 match b { a::B(_) => {} }
54a0048b
SL
74 match b { a::B(_b) => {} } //~ ERROR: field `0` of struct `a::B` is private
75 match b { a::B(1) => {} a::B(_) => {} } //~ ERROR: field `0` of struct `a::B` is private
1a4d82fc
JJ
76
77 let a::C(_, _) = c;
78 let a::C(_a, _) = c;
54a0048b
SL
79 let a::C(_, _b) = c; //~ ERROR: field `1` of struct `a::C` is private
80 let a::C(_a, _b) = c; //~ ERROR: field `1` of struct `a::C` is private
1a4d82fc
JJ
81 match c { a::C(_, _) => {} }
82 match c { a::C(_a, _) => {} }
54a0048b
SL
83 match c { a::C(_, _b) => {} } //~ ERROR: field `1` of struct `a::C` is private
84 match c { a::C(_a, _b) => {} } //~ ERROR: field `1` of struct `a::C` is private
1a4d82fc
JJ
85
86 let a::D(_) = d;
87 let a::D(_d) = d;
88 match d { a::D(_) => {} }
89 match d { a::D(_d) => {} }
90 match d { a::D(1) => {} a::D(_) => {} }
91
92 let a2 = a::A; //~ ERROR: cannot invoke tuple struct constructor
93 let b2 = a::B; //~ ERROR: cannot invoke tuple struct constructor
94 let c2 = a::C; //~ ERROR: cannot invoke tuple struct constructor
95 let d2 = a::D;
96}
97
98fn xcrate() {
99 let a = other::A(()); //~ ERROR: cannot invoke tuple struct constructor
100 let b = other::B(2); //~ ERROR: cannot invoke tuple struct constructor
101 let c = other::C(2, 3); //~ ERROR: cannot invoke tuple struct constructor
102 let d = other::D(4);
103
54a0048b 104 let other::A(()) = a; //~ ERROR: field `0` of struct `other::A` is private
1a4d82fc
JJ
105 let other::A(_) = a;
106 match a { other::A(()) => {} }
54a0048b 107 //~^ ERROR: field `0` of struct `other::A` is private
1a4d82fc
JJ
108 match a { other::A(_) => {} }
109
110 let other::B(_) = b;
54a0048b 111 let other::B(_b) = b; //~ ERROR: field `0` of struct `other::B` is private
1a4d82fc
JJ
112 match b { other::B(_) => {} }
113 match b { other::B(_b) => {} }
54a0048b 114 //~^ ERROR: field `0` of struct `other::B` is private
1a4d82fc 115 match b { other::B(1) => {} other::B(_) => {} }
54a0048b 116 //~^ ERROR: field `0` of struct `other::B` is private
1a4d82fc
JJ
117
118 let other::C(_, _) = c;
119 let other::C(_a, _) = c;
54a0048b
SL
120 let other::C(_, _b) = c; //~ ERROR: field `1` of struct `other::C` is private
121 let other::C(_a, _b) = c; //~ ERROR: field `1` of struct `other::C` is private
1a4d82fc
JJ
122 match c { other::C(_, _) => {} }
123 match c { other::C(_a, _) => {} }
124 match c { other::C(_, _b) => {} }
54a0048b 125 //~^ ERROR: field `1` of struct `other::C` is private
1a4d82fc 126 match c { other::C(_a, _b) => {} }
54a0048b 127 //~^ ERROR: field `1` of struct `other::C` is private
1a4d82fc
JJ
128
129 let other::D(_) = d;
130 let other::D(_d) = d;
131 match d { other::D(_) => {} }
132 match d { other::D(_d) => {} }
133 match d { other::D(1) => {} other::D(_) => {} }
134
135 let a2 = other::A; //~ ERROR: cannot invoke tuple struct constructor
136 let b2 = other::B; //~ ERROR: cannot invoke tuple struct constructor
137 let c2 = other::C; //~ ERROR: cannot invoke tuple struct constructor
138 let d2 = other::D;
139}
140
141fn main() {}