]> git.lizzy.rs Git - rust.git/blob - src/test/ui/privacy/private-in-public-assoc-ty.rs
update ui tests
[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 { type A; }
13
14     // "Private-in-public in associated types is hard error" in RFC 2145
15     // applies only to the aliased types, not bounds.
16     pub trait PubTr {
17         //~^ WARN private trait `m::PrivTr` in public interface
18         //~| WARN this was previously accepted
19         //~| WARN private type `m::Priv` in public interface
20         //~| WARN this was previously accepted
21         type Alias1: PrivTr;
22         type Alias2: PubTrAux1<Priv> = u8;
23         type Alias3: PubTrAux2<A = Priv> = u8;
24
25         type Alias4 = Priv;
26         //~^ ERROR private type `m::Priv` in public interface
27
28         type Exist;
29         fn infer_exist() -> Self::Exist;
30     }
31     impl PubTr for u8 {
32         type Alias1 = Priv;
33         //~^ ERROR private type `m::Priv` in public interface
34
35         type Exist = impl PrivTr;
36         //~^ ERROR private trait `m::PrivTr` in public interface
37         fn infer_exist() -> Self::Exist { Priv }
38     }
39 }
40
41 fn main() {}