2017-11-18 17:32:24 +00:00
|
|
|
// Private types and traits are not allowed in interfaces of associated types.
|
|
|
|
// This test also ensures that the checks are performed even inside private modules.
|
|
|
|
|
2019-07-29 23:11:58 +00:00
|
|
|
#![feature(associated_type_defaults)]
|
2023-04-12 13:32:15 +00:00
|
|
|
#![feature(impl_trait_in_assoc_type)]
|
2017-11-18 17:32:24 +00:00
|
|
|
|
|
|
|
mod m {
|
|
|
|
struct Priv;
|
|
|
|
trait PrivTr {}
|
|
|
|
impl PrivTr for Priv {}
|
|
|
|
pub trait PubTrAux1<T> {}
|
2020-05-10 10:57:58 +00:00
|
|
|
pub trait PubTrAux2 {
|
|
|
|
type A;
|
|
|
|
}
|
2019-06-13 19:36:15 +00:00
|
|
|
impl<T> PubTrAux1<T> for u8 {}
|
|
|
|
impl PubTrAux2 for u8 {
|
|
|
|
type A = Priv;
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR private type `Priv` in public interface
|
2019-06-13 19:36:15 +00:00
|
|
|
}
|
2017-11-18 17:32:24 +00:00
|
|
|
|
|
|
|
// "Private-in-public in associated types is hard error" in RFC 2145
|
|
|
|
// applies only to the aliased types, not bounds.
|
|
|
|
pub trait PubTr {
|
2020-09-07 09:01:45 +00:00
|
|
|
type Alias1: PrivTr;
|
2023-06-19 14:06:00 +00:00
|
|
|
//~^ WARN trait `PrivTr` is more private than the item `PubTr::Alias1`
|
2017-11-18 17:32:24 +00:00
|
|
|
type Alias2: PubTrAux1<Priv> = u8;
|
2023-06-19 14:06:00 +00:00
|
|
|
//~^ WARN type `Priv` is more private than the item `PubTr::Alias2`
|
2017-11-18 17:32:24 +00:00
|
|
|
type Alias3: PubTrAux2<A = Priv> = u8;
|
2023-06-19 14:06:00 +00:00
|
|
|
//~^ WARN type `Priv` is more private than the item `PubTr::Alias3`
|
2017-11-18 17:32:24 +00:00
|
|
|
|
|
|
|
type Alias4 = Priv;
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR private type `Priv` in public interface
|
2019-01-15 22:47:49 +00:00
|
|
|
|
|
|
|
type Exist;
|
|
|
|
fn infer_exist() -> Self::Exist;
|
2017-11-18 17:32:24 +00:00
|
|
|
}
|
|
|
|
impl PubTr for u8 {
|
|
|
|
type Alias1 = Priv;
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR private type `Priv` in public interface
|
2019-01-15 22:47:49 +00:00
|
|
|
|
2019-07-29 23:11:58 +00:00
|
|
|
type Exist = impl PrivTr;
|
2020-09-02 07:40:56 +00:00
|
|
|
//~^ ERROR private trait `PrivTr` in public interface
|
2020-05-10 10:57:58 +00:00
|
|
|
fn infer_exist() -> Self::Exist {
|
|
|
|
Priv
|
|
|
|
}
|
2017-11-18 17:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|