1 // Private types and traits are not allowed in public interfaces.
2 // This test also ensures that the checks are performed even inside private modules.
4 #![feature(associated_type_defaults)]
5 #![deny(private_in_public)]
6 #![allow(improper_ctypes)]
15 pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
16 //~^ WARNING hard error
18 V1(Priv), //~ ERROR private type `types::Priv` in public interface
19 //~^ WARNING hard error
20 V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
21 //~^ WARNING hard error
24 const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
25 //~^ WARNING hard error
26 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
27 fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
28 //~^ WARNING hard error
29 fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
30 //~^ WARNING hard error
33 pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
34 //~^ WARNING hard error
35 pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
36 //~^ WARNING hard error
37 pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
38 //~^ WARNING hard error
41 type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
50 pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
51 //~| WARNING hard error
52 //~| WARNING bounds on generic parameters are not enforced in type aliases
53 pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
54 //~^ WARNING hard error
55 pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
56 //~^ WARNING hard error
59 //~^ ERROR private trait `traits::PrivTr` in public interface
60 //~| WARNING hard error
61 fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
62 //~^ WARNING hard error
64 impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
65 //~^ WARNING hard error
66 impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
74 pub type Alias<T> where T: PrivTr = T;
75 //~^ ERROR private trait `traits_where::PrivTr` in public interface
76 //~| WARNING hard error
77 //~| WARNING where clauses are not enforced in type aliases
78 pub trait Tr2<T> where T: PrivTr {}
79 //~^ ERROR private trait `traits_where::PrivTr` in public interface
80 //~| WARNING hard error
82 fn f<T>(arg: T) where T: PrivTr {}
83 //~^ ERROR private trait `traits_where::PrivTr` in public interface
84 //~| WARNING hard error
86 impl<T> Pub<T> where T: PrivTr {}
87 //~^ ERROR private trait `traits_where::PrivTr` in public interface
88 //~| WARNING hard error
89 impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates
93 struct Priv<T = u8>(T);
94 pub struct Pub<T = u8>(T);
98 pub trait Tr1: PrivTr<Pub> {}
99 //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
100 //~| WARNING hard error
101 pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
102 //~^ WARNING hard error
103 pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
104 //~^ WARNING hard error
105 pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
106 //~^ WARNING hard error
120 pub fn f(arg: Priv) {} // OK
122 impl PrivTr for Priv {
123 type Alias = Priv; // OK
125 impl PubTr for Priv {
126 type Alias = Priv; // OK
128 impl PrivTr for Pub {
129 type Alias = Priv; // OK
132 type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
137 struct Priv<T = u8>(T);
138 pub struct Pub<T = u8>(T);
139 trait PrivTr<T = u8> {
142 pub trait PubTr<T = u8> {
147 pub fn f(arg: Priv) {} // OK
150 pub fn f(arg: Priv) {} // OK
152 impl PrivTr<Pub> for Priv {
153 type Alias = Priv; // OK
155 impl PubTr<Priv> for Priv {
156 type Alias = Priv; // OK
158 impl PubTr for Priv<Pub> {
159 type Alias = Priv; // OK
161 impl PubTr for [Priv; 1] {
162 type Alias = Priv; // OK
164 impl PubTr for Pub<Priv> {
165 type Alias = Priv; // OK
167 impl PrivTr<Pub> for Pub {
168 type Alias = Priv; // OK
170 impl PubTr<Priv> for Pub {
171 type Alias = Priv; // OK
181 pub trait PubTr<T = u8> {
186 use self::m::Pub1 as PrivUseAlias;
187 use self::m::PubTr as PrivUseAliasTr;
188 type PrivAlias = m::Pub2;
192 impl PrivTr for Priv {
193 type AssocAlias = m::Pub3;
196 pub fn f1(arg: PrivUseAlias) {} // OK
197 pub fn f2(arg: PrivAlias) {} // OK
199 pub trait Tr1: PrivUseAliasTr {} // OK
200 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
203 pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
204 //~^ WARNING hard error
206 impl PrivUseAliasTr for PrivUseAlias {
207 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
209 impl PrivUseAliasTr for PrivAlias {
210 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
212 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
213 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
215 impl PrivUseAliasTr for Option<<Priv as PrivTr>::AssocAlias> {
216 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
218 impl PrivUseAliasTr for (<Priv as PrivTr>::AssocAlias, Priv) {
219 type Check = Priv; // OK
221 impl PrivUseAliasTr for Option<(<Priv as PrivTr>::AssocAlias, Priv)> {
222 type Check = Priv; // OK
232 trait PrivTr1<T = u8> {
236 use self::Priv1 as PrivUseAlias;
237 use self::PrivTr1 as PrivUseAliasTr;
238 type PrivAlias = Priv2;
242 impl PrivTr for Priv {
243 type AssocAlias = Priv3;
246 pub trait Tr1: PrivUseAliasTr {}
247 //~^ ERROR private trait `PrivTr1` in public interface
248 //~| WARNING hard error
249 pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
250 //~^ ERROR private trait `PrivTr1<Priv2>` in public interface
251 //~| WARNING hard error
252 //~| ERROR private type `Priv2` in public interface
253 //~| WARNING hard error
256 pub fn f(arg: Priv) {} // OK
259 pub fn f(arg: Priv) {} // OK
261 impl PrivUseAliasTr for PrivUseAlias {
262 type Check = Priv; // OK
264 impl PrivUseAliasTr for PrivAlias {
265 type Check = Priv; // OK
267 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
268 type Check = Priv; // OK
274 type PrivAliasGeneric<T = Priv> = T;
275 type Result<T> = ::std::result::Result<T, Priv>;
277 pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error