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(rustc_attrs)]
15 #![feature(associated_consts)]
16 #![feature(associated_type_defaults)]
18 #![allow(unused_variables)]
19 #![allow(improper_ctypes)]
28 pub type Alias = Priv; //~ WARN private type in public interface
29 //~^ WARNING hard error
31 V1(Priv), //~ WARN private type in public interface
32 //~^ WARNING hard error
33 V2 { field: Priv }, //~ WARN private type in public interface
34 //~^ WARNING hard error
37 const C: Priv = Priv; //~ WARN private type in public interface
38 //~^ WARNING hard error
39 type Alias = Priv; //~ WARN private type in public interface
40 //~^ WARNING hard error
41 fn f1(arg: Priv) {} //~ WARN private type in public interface
42 //~^ WARNING hard error
43 fn f2() -> Priv { panic!() } //~ WARN private type in public interface
44 //~^ WARNING hard error
47 pub static ES: Priv; //~ WARN private type in public interface
48 //~^ WARNING hard error
49 pub fn ef1(arg: Priv); //~ WARN private type in public interface
50 //~^ WARNING hard error
51 pub fn ef2() -> Priv; //~ WARN private type in public interface
52 //~^ WARNING hard error
55 type Alias = Priv; //~ WARN private type in public interface
56 //~^ WARNING hard error
65 pub type Alias<T: PrivTr> = T; //~ WARN private trait in public interface
66 //~^ WARN trait bounds are not (yet) enforced in type definitions
67 //~| WARNING hard error
68 pub trait Tr1: PrivTr {} //~ WARN private trait in public interface
69 //~^ WARNING hard error
70 pub trait Tr2<T: PrivTr> {} //~ WARN private trait in public interface
71 //~^ WARNING hard error
73 type Alias: PrivTr; //~ WARN private trait in public interface
74 //~^ WARNING hard error
75 fn f<T: PrivTr>(arg: T) {} //~ WARN private trait in public interface
76 //~^ WARNING hard error
78 impl<T: PrivTr> Pub<T> {} //~ WARN private trait in public interface
79 //~^ WARNING hard error
80 impl<T: PrivTr> PubTr for Pub<T> {} //~ WARN private trait in public interface
81 //~^ WARNING hard error
89 pub type Alias<T> where T: PrivTr = T; //~ WARN private trait in public interface
90 //~^ WARNING hard error
91 pub trait Tr2<T> where T: PrivTr {} //~ WARN private trait in public interface
92 //~^ WARNING hard error
94 fn f<T>(arg: T) where T: PrivTr {} //~ WARN private trait in public interface
95 //~^ WARNING hard error
97 impl<T> Pub<T> where T: PrivTr {} //~ WARN private trait in public interface
98 //~^ WARNING hard error
99 impl<T> PubTr for Pub<T> where T: PrivTr {} //~ WARN private trait in public interface
100 //~^ WARNING hard error
104 struct Priv<T = u8>(T);
105 pub struct Pub<T = u8>(T);
107 pub trait PubTr<T> {}
109 pub trait Tr1: PrivTr<Pub> {} //~ WARN private trait in public interface
110 //~^ WARNING hard error
111 pub trait Tr2: PubTr<Priv> {} //~ WARN private type in public interface
112 //~^ WARNING hard error
113 pub trait Tr3: PubTr<[Priv; 1]> {} //~ WARN private type in public interface
114 //~^ WARNING hard error
115 pub trait Tr4: PubTr<Pub<Priv>> {} //~ WARN private type in public interface
116 //~^ WARNING hard error
130 pub fn f(arg: Priv) {} // OK
132 impl PrivTr for Priv {
133 type Alias = Priv; // OK
135 impl PubTr for Priv {
136 type Alias = Priv; // OK
138 impl PrivTr for Pub {
139 type Alias = Priv; // OK
142 type Alias = Priv; //~ WARN private type in public interface
143 //~^ WARNING hard error
148 struct Priv<T = u8>(T);
149 pub struct Pub<T = u8>(T);
150 trait PrivTr<T = u8> {
153 pub trait PubTr<T = u8> {
158 pub fn f(arg: Priv) {} // OK
161 pub fn f(arg: Priv) {} // OK
163 impl PrivTr<Pub> for Priv {
164 type Alias = Priv; // OK
166 impl PubTr<Priv> for Priv {
167 type Alias = Priv; // OK
169 impl PubTr for Priv<Pub> {
170 type Alias = Priv; // OK
172 impl PubTr for [Priv; 1] {
173 type Alias = Priv; // OK
175 impl PubTr for Pub<Priv> {
176 type Alias = Priv; // OK
178 impl PrivTr<Pub> for Pub {
179 type Alias = Priv; // OK
181 impl PubTr<Priv> for Pub {
182 type Alias = Priv; // OK
192 pub trait PubTr<T = u8> {
197 use self::m::Pub1 as PrivUseAlias;
198 use self::m::PubTr as PrivUseAliasTr;
199 type PrivAlias = m::Pub2;
203 impl PrivTr for Priv {
204 type AssocAlias = m::Pub3;
207 pub fn f1(arg: PrivUseAlias) {} // OK
209 pub trait Tr1: PrivUseAliasTr {} // OK
210 // This should be OK, if type aliases are substituted
211 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private type in public interface
212 //~^ WARNING hard error
215 pub fn f(arg: Priv) {} //~ WARN private type in public interface
216 //~^ WARNING hard error
218 // This doesn't even parse
219 // impl <Priv as PrivTr>::AssocAlias {
220 // pub fn f(arg: Priv) {} // WARN private type in public interface
222 impl PrivUseAliasTr for PrivUseAlias {
223 type Check = Priv; //~ WARN private type in public interface
224 //~^ WARNING hard error
226 impl PrivUseAliasTr for PrivAlias {
227 type Check = Priv; //~ WARN private type in public interface
228 //~^ WARNING hard error
230 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
231 type Check = Priv; //~ WARN private type in public interface
232 //~^ WARNING hard error
242 trait PrivTr1<T = u8> {
246 use self::Priv1 as PrivUseAlias;
247 use self::PrivTr1 as PrivUseAliasTr;
248 type PrivAlias = Priv2;
252 impl PrivTr for Priv {
253 type AssocAlias = Priv3;
256 pub trait Tr1: PrivUseAliasTr {} //~ WARN private trait in public interface
257 //~^ WARNING hard error
258 pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private trait in public interface
259 //~^ WARN private type in public interface
260 //~| WARNING hard error
261 //~| WARNING hard error
264 pub fn f(arg: Priv) {} // OK
267 pub fn f(arg: Priv) {} // OK
269 // This doesn't even parse
270 // impl <Priv as PrivTr>::AssocAlias {
271 // pub fn f(arg: Priv) {} // OK
273 impl PrivUseAliasTr for PrivUseAlias {
274 type Check = Priv; // OK
276 impl PrivUseAliasTr for PrivAlias {
277 type Check = Priv; // OK
279 impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
280 type Check = Priv; // OK
286 type PrivAliasGeneric<T = Priv> = T;
287 type Result<T> = ::std::result::Result<T, Priv>;
291 fn main() {} //~ ERROR compilation successful