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.
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.
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.
14 #![feature(associated_consts)]
15 #![feature(associated_type_defaults)]
16 #![deny(private_in_public)]
18 #![allow(improper_ctypes)]
27 pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
28 //~^ WARNING hard error
30 V1(Priv), //~ ERROR private type `types::Priv` in public interface
31 //~^ WARNING hard error
32 V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
33 //~^ WARNING hard error
36 const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
37 //~^ WARNING hard error
38 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
39 //~^ WARNING hard error
40 fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
41 //~^ WARNING hard error
42 fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
43 //~^ WARNING hard error
46 pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
47 //~^ WARNING hard error
48 pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
49 //~^ WARNING hard error
50 pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
51 //~^ WARNING hard error
54 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
55 //~^ WARNING hard error
64 pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
65 //~^ WARN trait bounds are not (yet) enforced in type definitions
66 //~| WARNING hard error
67 pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
68 //~^ WARNING hard error
69 pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
70 //~^ WARNING hard error
72 //~^ ERROR private trait `traits::PrivTr` in public interface
73 //~| WARNING hard error
75 fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
76 //~^ WARNING hard error
78 impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
79 //~^ WARNING hard error
80 impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
81 //~^ WARNING hard error
89 pub type Alias<T> where T: PrivTr = T;
90 //~^ ERROR private trait `traits_where::PrivTr` in public interface
91 //~| WARNING hard error
93 pub trait Tr2<T> where T: PrivTr {}
94 //~^ ERROR private trait `traits_where::PrivTr` in public interface
95 //~| WARNING hard error
97 fn f<T>(arg: T) where T: PrivTr {}
98 //~^ ERROR private trait `traits_where::PrivTr` in public interface
99 //~| WARNING hard error
101 impl<T> Pub<T> where T: PrivTr {}
102 //~^ ERROR private trait `traits_where::PrivTr` in public interface
103 //~| WARNING hard error
104 impl<T> PubTr for Pub<T> where T: PrivTr {}
105 //~^ ERROR private trait `traits_where::PrivTr` in public interface
106 //~| WARNING hard error
110 struct Priv<T = u8>(T);
111 pub struct Pub<T = u8>(T);
113 pub trait PubTr<T> {}
115 pub trait Tr1: PrivTr<Pub> {}
116 //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
117 //~| WARNING hard error
118 pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
119 //~^ WARNING hard error
120 pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
121 //~^ WARNING hard error
122 pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
123 //~^ WARNING hard error
137 pub fn f(arg: Priv) {} // OK
139 impl PrivTr for Priv {
140 type Alias = Priv; // OK
142 impl PubTr for Priv {
143 type Alias = Priv; // OK
145 impl PrivTr for Pub {
146 type Alias = Priv; // OK
149 type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
150 //~^ WARNING hard error
155 struct Priv<T = u8>(T);
156 pub struct Pub<T = u8>(T);
157 trait PrivTr<T = u8> {
160 pub trait PubTr<T = u8> {
165 pub fn f(arg: Priv) {} // OK
168 pub fn f(arg: Priv) {} // OK
170 impl PrivTr<Pub> for Priv {
171 type Alias = Priv; // OK
173 impl PubTr<Priv> for Priv {
174 type Alias = Priv; // OK
176 impl PubTr for Priv<Pub> {
177 type Alias = Priv; // OK
179 impl PubTr for [Priv; 1] {
180 type Alias = Priv; // OK
182 impl PubTr for Pub<Priv> {
183 type Alias = Priv; // OK
185 impl PrivTr<Pub> for Pub {
186 type Alias = Priv; // OK
188 impl PubTr<Priv> for Pub {
189 type Alias = Priv; // OK
199 pub trait PubTr<T = u8> {
204 use self::m::Pub1 as PrivUseAlias;
205 use self::m::PubTr as PrivUseAliasTr;
206 type PrivAlias = m::Pub2;
210 impl PrivTr for Priv {
211 type AssocAlias = m::Pub3;
214 pub fn f1(arg: PrivUseAlias) {} // OK
215 pub fn f2(arg: PrivAlias) {} // OK
217 pub trait Tr1: PrivUseAliasTr {} // OK
218 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
221 pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
222 //~^ WARNING hard error
224 // This doesn't even parse
225 // impl <Priv as PrivTr>::AssocAlias {
226 // pub fn f(arg: Priv) {} // ERROR private type `aliases_pub::Priv` in public interface
228 impl PrivUseAliasTr for PrivUseAlias {
229 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
230 //~^ WARNING hard error
232 impl PrivUseAliasTr for PrivAlias {
233 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
234 //~^ WARNING hard error
236 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
237 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
238 //~^ WARNING hard error
248 trait PrivTr1<T = u8> {
252 use self::Priv1 as PrivUseAlias;
253 use self::PrivTr1 as PrivUseAliasTr;
254 type PrivAlias = Priv2;
258 impl PrivTr for Priv {
259 type AssocAlias = Priv3;
262 pub trait Tr1: PrivUseAliasTr {}
263 //~^ ERROR private trait `aliases_priv::PrivTr1` in public interface
264 //~| WARNING hard error
265 pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
266 //~^ ERROR private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface
267 //~| WARNING hard error
268 //~| ERROR private type `aliases_priv::Priv2` in public interface
269 //~| WARNING hard error
272 pub fn f(arg: Priv) {} // OK
275 pub fn f(arg: Priv) {} // OK
277 // This doesn't even parse
278 // impl <Priv as PrivTr>::AssocAlias {
279 // pub fn f(arg: Priv) {} // OK
281 impl PrivUseAliasTr for PrivUseAlias {
282 type Check = Priv; // OK
284 impl PrivUseAliasTr for PrivAlias {
285 type Check = Priv; // OK
287 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
288 type Check = Priv; // OK
294 type PrivAliasGeneric<T = Priv> = T;
295 type Result<T> = ::std::result::Result<T, Priv>;
297 pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error