]> git.proxmox.com Git - rustc.git/blame - src/test/ui/privacy/private-in-public-warn.rs
Update upstream source from tag 'upstream/1.30.0_beta.7+dfsg1'
[rustc.git] / src / test / ui / privacy / private-in-public-warn.rs
CommitLineData
9cc50fc6
SL
1// Copyright 2015 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// Private types and traits are not allowed in public interfaces.
12// This test also ensures that the checks are performed even inside private modules.
13
9cc50fc6 14#![feature(associated_type_defaults)]
5bcae85e 15#![deny(private_in_public)]
9cc50fc6
SL
16#![allow(improper_ctypes)]
17
18mod types {
19 struct Priv;
20 pub struct Pub;
21 pub trait PubTr {
22 type Alias;
23 }
24
476ff2be 25 pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
9cc50fc6
SL
26 //~^ WARNING hard error
27 pub enum E {
476ff2be 28 V1(Priv), //~ ERROR private type `types::Priv` in public interface
9cc50fc6 29 //~^ WARNING hard error
476ff2be 30 V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
9cc50fc6
SL
31 //~^ WARNING hard error
32 }
33 pub trait Tr {
476ff2be 34 const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
9cc50fc6 35 //~^ WARNING hard error
476ff2be 36 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
476ff2be 37 fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
9cc50fc6 38 //~^ WARNING hard error
476ff2be 39 fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
9cc50fc6
SL
40 //~^ WARNING hard error
41 }
42 extern {
476ff2be 43 pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
9cc50fc6 44 //~^ WARNING hard error
476ff2be 45 pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
9cc50fc6 46 //~^ WARNING hard error
476ff2be 47 pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
9cc50fc6
SL
48 //~^ WARNING hard error
49 }
50 impl PubTr for Pub {
476ff2be 51 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
9cc50fc6
SL
52 }
53}
54
55mod traits {
56 trait PrivTr {}
57 pub struct Pub<T>(T);
58 pub trait PubTr {}
59
476ff2be 60 pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6 61 //~| WARNING hard error
476ff2be 62 pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6 63 //~^ WARNING hard error
476ff2be 64 pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6
SL
65 //~^ WARNING hard error
66 pub trait Tr3 {
476ff2be
SL
67 //~^ ERROR private trait `traits::PrivTr` in public interface
68 //~| WARNING hard error
69 type Alias: PrivTr;
70 fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6
SL
71 //~^ WARNING hard error
72 }
476ff2be 73 impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6 74 //~^ WARNING hard error
476ff2be 75 impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
9cc50fc6
SL
76 //~^ WARNING hard error
77}
78
79mod traits_where {
80 trait PrivTr {}
81 pub struct Pub<T>(T);
82 pub trait PubTr {}
83
476ff2be
SL
84 pub type Alias<T> where T: PrivTr = T;
85 //~^ ERROR private trait `traits_where::PrivTr` in public interface
86 //~| WARNING hard error
87 pub trait Tr2<T> where T: PrivTr {}
88 //~^ ERROR private trait `traits_where::PrivTr` in public interface
89 //~| WARNING hard error
9cc50fc6 90 pub trait Tr3 {
476ff2be
SL
91 fn f<T>(arg: T) where T: PrivTr {}
92 //~^ ERROR private trait `traits_where::PrivTr` in public interface
93 //~| WARNING hard error
9cc50fc6 94 }
476ff2be
SL
95 impl<T> Pub<T> where T: PrivTr {}
96 //~^ ERROR private trait `traits_where::PrivTr` in public interface
97 //~| WARNING hard error
98 impl<T> PubTr for Pub<T> where T: PrivTr {}
99 //~^ ERROR private trait `traits_where::PrivTr` in public interface
100 //~| WARNING hard error
9cc50fc6
SL
101}
102
103mod generics {
104 struct Priv<T = u8>(T);
105 pub struct Pub<T = u8>(T);
106 trait PrivTr<T> {}
107 pub trait PubTr<T> {}
108
476ff2be
SL
109 pub trait Tr1: PrivTr<Pub> {}
110 //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
111 //~| WARNING hard error
112 pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
9cc50fc6 113 //~^ WARNING hard error
476ff2be 114 pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
9cc50fc6 115 //~^ WARNING hard error
476ff2be 116 pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
9cc50fc6
SL
117 //~^ WARNING hard error
118}
119
120mod impls {
121 struct Priv;
122 pub struct Pub;
123 trait PrivTr {
124 type Alias;
125 }
126 pub trait PubTr {
127 type Alias;
128 }
129
130 impl Priv {
131 pub fn f(arg: Priv) {} // OK
132 }
133 impl PrivTr for Priv {
134 type Alias = Priv; // OK
135 }
136 impl PubTr for Priv {
137 type Alias = Priv; // OK
138 }
139 impl PrivTr for Pub {
140 type Alias = Priv; // OK
141 }
142 impl PubTr for Pub {
476ff2be 143 type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
9cc50fc6
SL
144 }
145}
146
147mod impls_generics {
148 struct Priv<T = u8>(T);
149 pub struct Pub<T = u8>(T);
150 trait PrivTr<T = u8> {
151 type Alias;
152 }
153 pub trait PubTr<T = u8> {
154 type Alias;
155 }
156
157 impl Priv<Pub> {
158 pub fn f(arg: Priv) {} // OK
159 }
160 impl Pub<Priv> {
161 pub fn f(arg: Priv) {} // OK
162 }
163 impl PrivTr<Pub> for Priv {
164 type Alias = Priv; // OK
165 }
166 impl PubTr<Priv> for Priv {
167 type Alias = Priv; // OK
168 }
169 impl PubTr for Priv<Pub> {
170 type Alias = Priv; // OK
171 }
172 impl PubTr for [Priv; 1] {
173 type Alias = Priv; // OK
174 }
175 impl PubTr for Pub<Priv> {
176 type Alias = Priv; // OK
177 }
178 impl PrivTr<Pub> for Pub {
179 type Alias = Priv; // OK
180 }
181 impl PubTr<Priv> for Pub {
182 type Alias = Priv; // OK
183 }
184}
185
186mod aliases_pub {
187 struct Priv;
188 mod m {
189 pub struct Pub1;
190 pub struct Pub2;
191 pub struct Pub3;
192 pub trait PubTr<T = u8> {
193 type Check = u8;
194 }
195 }
196
197 use self::m::Pub1 as PrivUseAlias;
198 use self::m::PubTr as PrivUseAliasTr;
199 type PrivAlias = m::Pub2;
200 trait PrivTr {
54a0048b
SL
201 type AssocAlias;
202 }
203 impl PrivTr for Priv {
9cc50fc6
SL
204 type AssocAlias = m::Pub3;
205 }
9cc50fc6
SL
206
207 pub fn f1(arg: PrivUseAlias) {} // OK
5bcae85e 208 pub fn f2(arg: PrivAlias) {} // OK
9cc50fc6
SL
209
210 pub trait Tr1: PrivUseAliasTr {} // OK
5bcae85e 211 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
9cc50fc6
SL
212
213 impl PrivAlias {
476ff2be 214 pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
9cc50fc6
SL
215 //~^ WARNING hard error
216 }
9cc50fc6 217 impl PrivUseAliasTr for PrivUseAlias {
476ff2be 218 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
9cc50fc6
SL
219 }
220 impl PrivUseAliasTr for PrivAlias {
476ff2be 221 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
9cc50fc6
SL
222 }
223 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
476ff2be 224 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
9cc50fc6
SL
225 }
226}
227
228mod aliases_priv {
229 struct Priv;
230
231 struct Priv1;
232 struct Priv2;
233 struct Priv3;
234 trait PrivTr1<T = u8> {
235 type Check = u8;
236 }
237
238 use self::Priv1 as PrivUseAlias;
239 use self::PrivTr1 as PrivUseAliasTr;
240 type PrivAlias = Priv2;
241 trait PrivTr {
54a0048b
SL
242 type AssocAlias;
243 }
244 impl PrivTr for Priv {
9cc50fc6
SL
245 type AssocAlias = Priv3;
246 }
9cc50fc6 247
476ff2be
SL
248 pub trait Tr1: PrivUseAliasTr {}
249 //~^ ERROR private trait `aliases_priv::PrivTr1` in public interface
250 //~| WARNING hard error
251 pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
252 //~^ ERROR private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface
9cc50fc6 253 //~| WARNING hard error
476ff2be 254 //~| ERROR private type `aliases_priv::Priv2` in public interface
9cc50fc6
SL
255 //~| WARNING hard error
256
257 impl PrivUseAlias {
258 pub fn f(arg: Priv) {} // OK
259 }
260 impl PrivAlias {
261 pub fn f(arg: Priv) {} // OK
262 }
9cc50fc6
SL
263 impl PrivUseAliasTr for PrivUseAlias {
264 type Check = Priv; // OK
265 }
266 impl PrivUseAliasTr for PrivAlias {
267 type Check = Priv; // OK
268 }
269 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
270 type Check = Priv; // OK
271 }
272}
273
274mod aliases_params {
275 struct Priv;
276 type PrivAliasGeneric<T = Priv> = T;
277 type Result<T> = ::std::result::Result<T, Priv>;
5bcae85e
SL
278
279 pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
9cc50fc6
SL
280}
281
5bcae85e 282fn main() {}