]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/privacy/private-in-public.rs
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)]
13 pub const C
: Priv
= Priv
; //~ ERROR private type `types::Priv` in public interface
14 pub static S
: Priv
= Priv
; //~ ERROR private type `types::Priv` in public interface
15 pub fn f1(arg
: Priv
) {}
//~ ERROR private type `types::Priv` in public interface
16 pub fn f2() -> Priv { panic!() }
//~ ERROR private type `types::Priv` in public interface
17 pub struct S1(pub Priv
); //~ ERROR private type `types::Priv` in public interface
18 pub struct S2 { pub field: Priv }
//~ ERROR private type `types::Priv` in public interface
20 pub const C
: Priv
= Priv
; //~ ERROR private type `types::Priv` in public interface
21 pub fn f1(arg
: Priv
) {}
//~ ERROR private type `types::Priv` in public interface
22 pub fn f2() -> Priv { panic!() }
//~ ERROR private type `types::Priv` in public interface
31 pub enum E
<T
: PrivTr
> { V(T) }
//~ ERROR private trait `traits::PrivTr` in public interface
32 pub fn f
<T
: PrivTr
>(arg
: T
) {}
//~ ERROR private trait `traits::PrivTr` in public interface
33 pub struct S1
<T
: PrivTr
>(T
); //~ ERROR private trait `traits::PrivTr` in public interface
34 impl<T
: PrivTr
> Pub
<T
> { //~ ERROR private trait `traits::PrivTr` in public interface
35 pub fn f
<U
: PrivTr
>(arg
: U
) {}
//~ ERROR private trait `traits::PrivTr` in public interface
44 pub enum E
<T
> where T
: PrivTr { V(T) }
45 //~^ ERROR private trait `traits_where::PrivTr` in public interface
46 pub fn f
<T
>(arg
: T
) where T
: PrivTr {}
47 //~^ ERROR private trait `traits_where::PrivTr` in public interface
48 pub struct S1
<T
>(T
) where T
: PrivTr
;
49 //~^ ERROR private trait `traits_where::PrivTr` in public interface
50 impl<T
> Pub
<T
> where T
: PrivTr
{
51 //~^ ERROR private trait `traits_where::PrivTr` in public interface
52 pub fn f
<U
>(arg
: U
) where U
: PrivTr {}
53 //~^ ERROR private trait `traits_where::PrivTr` in public interface
58 struct Priv
<T
= u8>(T
);
59 pub struct Pub
<T
= u8>(T
);
63 pub fn f1(arg
: [Priv
; 1]) {}
//~ ERROR private type `generics::Priv` in public interface
64 pub fn f2(arg
: Pub
<Priv
>) {}
//~ ERROR private type `generics::Priv` in public interface
65 pub fn f3(arg
: Priv
<Pub
>) {}
66 //~^ ERROR private type `generics::Priv<generics::Pub>` in public interface
80 pub fn f(arg
: Priv
) {}
//~ ERROR private type `impls::Priv` in public interface
90 pub trait PubTr
<T
= u8> {
95 use self::m
::Pub1
as PrivUseAlias
;
96 use self::m
::PubTr
as PrivUseAliasTr
;
97 type PrivAlias
= m
::Pub2
;
101 impl PrivTr
for Priv {}
103 // This should be OK, but associated type aliases are not substituted yet
104 pub fn f3(arg
: <Priv
as PrivTr
>::Assoc
) {}
105 //~^ ERROR private trait `aliases_pub::PrivTr` in public interface
106 //~| ERROR private type `aliases_pub::Priv` in public interface
109 pub fn f(arg
: Priv
) {}
//~ ERROR private type `aliases_pub::Priv` in public interface
119 trait PrivTr1
<T
= u8> {
123 use self::Priv1
as PrivUseAlias
;
124 use self::PrivTr1
as PrivUseAliasTr
;
125 type PrivAlias
= Priv2
;
129 impl PrivTr
for Priv {}
131 pub fn f1(arg
: PrivUseAlias
) {}
//~ ERROR private type `Priv1` in public interface
132 pub fn f2(arg
: PrivAlias
) {}
//~ ERROR private type `Priv2` in public interface
133 pub fn f3(arg
: <Priv
as PrivTr
>::Assoc
) {}
134 //~^ ERROR private trait `aliases_priv::PrivTr` in public interface
135 //~| ERROR private type `aliases_priv::Priv` in public interface
140 type PrivAliasGeneric
<T
= Priv
> = T
;
141 type Result
<T
> = ::std
::result
::Result
<T
, Priv
>;
143 pub fn f2(arg
: PrivAliasGeneric
) {}
144 //~^ ERROR private type `aliases_params::Priv` in public interface
145 pub fn f3(arg
: Result
<u8>) {}
//~ ERROR private type `aliases_params::Priv` in public interface