privacy: Account for associated existential types

This commit is contained in:
Vadim Petrochenkov 2019-01-16 01:47:49 +03:00
parent daa53a52a2
commit d34b3e9bf2
4 changed files with 59 additions and 23 deletions

View file

@ -1,7 +1,7 @@
// 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.
#![feature(associated_type_defaults)]
#![feature(associated_type_defaults, existential_type)]
mod m {
struct Priv;
@ -23,10 +23,17 @@ mod m {
type Alias4 = Priv;
//~^ ERROR private type `m::Priv` in public interface
type Exist;
fn infer_exist() -> Self::Exist;
}
impl PubTr for u8 {
type Alias1 = Priv;
//~^ ERROR private type `m::Priv` in public interface
existential type Exist: PrivTr;
//~^ ERROR private trait `m::PrivTr` in public interface
fn infer_exist() -> Self::Exist { Priv }
}
}

View file

@ -6,7 +6,7 @@ LL | | //~^ WARN private trait `m::PrivTr` in public interface
LL | | //~| WARN this was previously accepted
LL | | //~| WARN private type `m::Priv` in public interface
... |
LL | | //~^ ERROR private type `m::Priv` in public interface
LL | | fn infer_exist() -> Self::Exist;
LL | | }
| |_____^
|
@ -22,7 +22,7 @@ LL | | //~^ WARN private trait `m::PrivTr` in public interface
LL | | //~| WARN this was previously accepted
LL | | //~| WARN private type `m::Priv` in public interface
... |
LL | | //~^ ERROR private type `m::Priv` in public interface
LL | | fn infer_exist() -> Self::Exist;
LL | | }
| |_____^
|
@ -39,7 +39,7 @@ LL | type Alias4 = Priv;
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `m::Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:28:9
--> $DIR/private-in-public-assoc-ty.rs:31:9
|
LL | struct Priv;
| - `m::Priv` declared as private
@ -47,6 +47,16 @@ LL | struct Priv;
LL | type Alias1 = Priv;
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error: aborting due to 2 previous errors
error[E0445]: private trait `m::PrivTr` in public interface
--> $DIR/private-in-public-assoc-ty.rs:34:9
|
LL | trait PrivTr {}
| - `m::PrivTr` declared as private
...
LL | existential type Exist: PrivTr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
For more information about this error, try `rustc --explain E0446`.
error: aborting due to 3 previous errors
Some errors occurred: E0445, E0446.
For more information about an error, try `rustc --explain E0445`.

View file

@ -12,4 +12,14 @@ fn check() -> Pub {
Priv
}
pub trait Trait {
type Pub: Default;
fn method() -> Self::Pub;
}
impl Trait for u8 {
existential type Pub: Default;
fn method() -> Self::Pub { Priv }
}
fn main() {}