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> {} //~ ERROR private trait `traits::PrivTr` in public interface
67 //~^ WARNING hard error
75 pub type Alias<T> where T: PrivTr = T;
76 //~^ ERROR private trait `traits_where::PrivTr` in public interface
77 //~| WARNING hard error
78 //~| WARNING where clauses are not enforced in type aliases
79 pub trait Tr2<T> where T: PrivTr {}
80 //~^ ERROR private trait `traits_where::PrivTr` in public interface
81 //~| WARNING hard error
83 fn f<T>(arg: T) where T: PrivTr {}
84 //~^ ERROR private trait `traits_where::PrivTr` in public interface
85 //~| WARNING hard error
87 impl<T> Pub<T> where T: PrivTr {}
88 //~^ ERROR private trait `traits_where::PrivTr` in public interface
89 //~| WARNING hard error
90 impl<T> PubTr for Pub<T> where T: PrivTr {}
91 //~^ ERROR private trait `traits_where::PrivTr` in public interface
92 //~| WARNING hard error
96 struct Priv<T = u8>(T);
97 pub struct Pub<T = u8>(T);
101 pub trait Tr1: PrivTr<Pub> {}
102 //~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
103 //~| WARNING hard error
104 pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
105 //~^ WARNING hard error
106 pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
107 //~^ WARNING hard error
108 pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
109 //~^ WARNING hard error
123 pub fn f(arg: Priv) {} // OK
125 impl PrivTr for Priv {
126 type Alias = Priv; // OK
128 impl PubTr for Priv {
129 type Alias = Priv; // OK
131 impl PrivTr for Pub {
132 type Alias = Priv; // OK
135 type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
140 struct Priv<T = u8>(T);
141 pub struct Pub<T = u8>(T);
142 trait PrivTr<T = u8> {
145 pub trait PubTr<T = u8> {
150 pub fn f(arg: Priv) {} // OK
153 pub fn f(arg: Priv) {} // OK
155 impl PrivTr<Pub> for Priv {
156 type Alias = Priv; // OK
158 impl PubTr<Priv> for Priv {
159 type Alias = Priv; // OK
161 impl PubTr for Priv<Pub> {
162 type Alias = Priv; // OK
164 impl PubTr for [Priv; 1] {
165 type Alias = Priv; // OK
167 impl PubTr for Pub<Priv> {
168 type Alias = Priv; // OK
170 impl PrivTr<Pub> for Pub {
171 type Alias = Priv; // OK
173 impl PubTr<Priv> for Pub {
174 type Alias = Priv; // OK
184 pub trait PubTr<T = u8> {
189 use self::m::Pub1 as PrivUseAlias;
190 use self::m::PubTr as PrivUseAliasTr;
191 type PrivAlias = m::Pub2;
195 impl PrivTr for Priv {
196 type AssocAlias = m::Pub3;
199 pub fn f1(arg: PrivUseAlias) {} // OK
200 pub fn f2(arg: PrivAlias) {} // OK
202 pub trait Tr1: PrivUseAliasTr {} // OK
203 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
206 pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
207 //~^ WARNING hard error
209 impl PrivUseAliasTr for PrivUseAlias {
210 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
212 impl PrivUseAliasTr for PrivAlias {
213 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
215 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
216 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
218 impl PrivUseAliasTr for Option<<Priv as PrivTr>::AssocAlias> {
219 type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
221 impl PrivUseAliasTr for (<Priv as PrivTr>::AssocAlias, Priv) {
222 type Check = Priv; // OK
224 impl PrivUseAliasTr for Option<(<Priv as PrivTr>::AssocAlias, Priv)> {
225 type Check = Priv; // OK
235 trait PrivTr1<T = u8> {
239 use self::Priv1 as PrivUseAlias;
240 use self::PrivTr1 as PrivUseAliasTr;
241 type PrivAlias = Priv2;
245 impl PrivTr for Priv {
246 type AssocAlias = Priv3;
249 pub trait Tr1: PrivUseAliasTr {}
250 //~^ ERROR private trait `PrivTr1` in public interface
251 //~| WARNING hard error
252 pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
253 //~^ ERROR private trait `PrivTr1<Priv2>` in public interface
254 //~| WARNING hard error
255 //~| ERROR private type `Priv2` in public interface
256 //~| WARNING hard error
259 pub fn f(arg: Priv) {} // OK
262 pub fn f(arg: Priv) {} // OK
264 impl PrivUseAliasTr for PrivUseAlias {
265 type Check = Priv; // OK
267 impl PrivUseAliasTr for PrivAlias {
268 type Check = Priv; // OK
270 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
271 type Check = Priv; // OK
277 type PrivAliasGeneric<T = Priv> = T;
278 type Result<T> = ::std::result::Result<T, Priv>;
280 pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error