]> git.lizzy.rs Git - rust.git/blob - src/test/ui/privacy/private-in-public-assoc-ty.rs
Rollup merge of #86747 - FabianWolff:issue-86653, r=GuillaumeGomez
[rust.git] / src / test / ui / privacy / private-in-public-assoc-ty.rs
1 // Private types and traits are not allowed in interfaces of associated types.
2 // This test also ensures that the checks are performed even inside private modules.
3
4 #![feature(associated_type_defaults)]
5 #![feature(type_alias_impl_trait)]
6
7 mod m {
8     struct Priv;
9     trait PrivTr {}
10     impl PrivTr for Priv {}
11     pub trait PubTrAux1<T> {}
12     pub trait PubTrAux2 {
13         type A;
14     }
15     impl<T> PubTrAux1<T> for u8 {}
16     impl PubTrAux2 for u8 {
17         type A = Priv;
18         //~^ ERROR private type `Priv` in public interface
19     }
20
21     // "Private-in-public in associated types is hard error" in RFC 2145
22     // applies only to the aliased types, not bounds.
23     pub trait PubTr {
24         type Alias1: PrivTr;
25         //~^ WARN private trait `PrivTr` in public interface
26         //~| WARN this was previously accepted
27         type Alias2: PubTrAux1<Priv> = u8;
28         //~^ WARN private type `Priv` in public interface
29         //~| WARN this was previously accepted
30         type Alias3: PubTrAux2<A = Priv> = u8;
31         //~^ WARN private type `Priv` in public interface
32         //~| WARN this was previously accepted
33
34         type Alias4 = Priv;
35         //~^ ERROR private type `Priv` in public interface
36
37         type Exist;
38         fn infer_exist() -> Self::Exist;
39     }
40     impl PubTr for u8 {
41         type Alias1 = Priv;
42         //~^ ERROR private type `Priv` in public interface
43
44         type Exist = impl PrivTr;
45         //~^ ERROR private trait `PrivTr` in public interface
46         fn infer_exist() -> Self::Exist {
47             Priv
48         }
49     }
50 }
51
52 fn main() {}