Skip to content

Commit

Permalink
rustc_privacy: switch private-in-public checking to Ty.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 28, 2016
1 parent fcdb4de commit 548e681
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 234 deletions.
332 changes: 183 additions & 149 deletions src/librustc_privacy/lib.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/test/compile-fail/E0445.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ trait Foo {
}

pub trait Bar : Foo {}
//~^ ERROR private trait in public interface [E0445]
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE private trait can't be public
pub struct Bar2<T: Foo>(pub T);
//~^ ERROR private trait in public interface [E0445]
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE private trait can't be public
pub fn foo<T: Foo> (t: T) {}
//~^ ERROR private trait in public interface [E0445]
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE private trait can't be public

fn main() {}
3 changes: 2 additions & 1 deletion src/test/compile-fail/issue-18389.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use std::any::TypeId;
trait Private<P, R> {
fn call(&self, p: P, r: R);
}
pub trait Public: Private< //~ ERROR private trait in public interface
pub trait Public: Private<
//~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
<Self as Public>::P,
<Self as Public>::R
> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-28514.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod inner {
fn b(&self) { }
}

pub trait C: A + B { //~ ERROR private trait in public interface
pub trait C: A + B { //~ ERROR private trait `inner::A` in public interface
//~^ WARN will become a hard error
fn c(&self) { }
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/issue-30079.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SemiPriv;
mod m1 {
struct Priv;
impl ::SemiPriv {
pub fn f(_: Priv) {} //~ ERROR private type in public interface
pub fn f(_: Priv) {} //~ ERROR private type `m1::Priv` in public interface
//~^ WARNING hard error
}

Expand All @@ -28,7 +28,7 @@ mod m1 {
mod m2 {
struct Priv;
impl ::std::ops::Deref for ::SemiPriv {
type Target = Priv; //~ ERROR private type in public interface
type Target = Priv; //~ ERROR private type `m2::Priv` in public interface
//~^ WARNING hard error
fn deref(&self) -> &Self::Target { unimplemented!() }
}
Expand All @@ -46,7 +46,7 @@ trait SemiPrivTrait {
mod m3 {
struct Priv;
impl ::SemiPrivTrait for () {
type Assoc = Priv; //~ ERROR private type in public interface
type Assoc = Priv; //~ ERROR private type `m3::Priv` in public interface
//~^ WARNING hard error
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/private-in-public-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod m1 {
struct Priv;

impl Pub {
pub fn f() -> Priv {Priv} //~ ERROR private type in public interface
pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface
}
}

Expand All @@ -24,7 +24,7 @@ mod m2 {
struct Priv;

impl Pub {
pub fn f() -> Priv {Priv} //~ ERROR private type in public interface
pub fn f() -> Priv {Priv} //~ ERROR private type `m2::Priv` in public interface
}
}

Expand Down
97 changes: 53 additions & 44 deletions src/test/compile-fail/private-in-public-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ mod types {
type Alias;
}

pub type Alias = Priv; //~ ERROR private type in public interface
pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub enum E {
V1(Priv), //~ ERROR private type in public interface
V1(Priv), //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
V2 { field: Priv }, //~ ERROR private type in public interface
V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
}
pub trait Tr {
const C: Priv = Priv; //~ ERROR private type in public interface
const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
type Alias = Priv; //~ ERROR private type in public interface
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
fn f1(arg: Priv) {} //~ ERROR private type in public interface
fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
fn f2() -> Priv { panic!() } //~ ERROR private type in public interface
fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
}
extern {
pub static ES: Priv; //~ ERROR private type in public interface
pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub fn ef1(arg: Priv); //~ ERROR private type in public interface
pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub fn ef2() -> Priv; //~ ERROR private type in public interface
pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
}
impl PubTr for Pub {
type Alias = Priv; //~ ERROR private type in public interface
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
}
}
Expand All @@ -61,22 +61,23 @@ mod traits {
pub struct Pub<T>(T);
pub trait PubTr {}

pub type Alias<T: PrivTr> = T; //~ ERROR private trait in public interface
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARN trait bounds are not (yet) enforced in type definitions
//~| WARNING hard error
pub trait Tr1: PrivTr {} //~ ERROR private trait in public interface
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait in public interface
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
pub trait Tr3 {
type Alias: PrivTr; //~ ERROR private trait in public interface
//~^ WARNING hard error
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait in public interface
//~^ ERROR private trait `traits::PrivTr` in public interface
//~| WARNING hard error
type Alias: PrivTr;
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
}
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait in public interface
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait in public interface
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
}

Expand All @@ -85,18 +86,23 @@ mod traits_where {
pub struct Pub<T>(T);
pub trait PubTr {}

pub type Alias<T> where T: PrivTr = T; //~ ERROR private trait in public interface
//~^ WARNING hard error
pub trait Tr2<T> where T: PrivTr {} //~ ERROR private trait in public interface
//~^ WARNING hard error
pub type Alias<T> where T: PrivTr = T;
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
pub trait Tr2<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
pub trait Tr3 {
fn f<T>(arg: T) where T: PrivTr {} //~ ERROR private trait in public interface
//~^ WARNING hard error
fn f<T>(arg: T) where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
}
impl<T> Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
//~^ WARNING hard error
impl<T> PubTr for Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
//~^ WARNING hard error
impl<T> Pub<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
impl<T> PubTr for Pub<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
}

mod generics {
Expand All @@ -105,13 +111,14 @@ mod generics {
trait PrivTr<T> {}
pub trait PubTr<T> {}

pub trait Tr1: PrivTr<Pub> {} //~ ERROR private trait in public interface
//~^ WARNING hard error
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type in public interface
pub trait Tr1: PrivTr<Pub> {}
//~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
//~| WARNING hard error
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type in public interface
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type in public interface
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
}

Expand All @@ -138,7 +145,7 @@ mod impls {
type Alias = Priv; // OK
}
impl PubTr for Pub {
type Alias = Priv; //~ ERROR private type in public interface
type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
//~^ WARNING hard error
}
}
Expand Down Expand Up @@ -210,23 +217,23 @@ mod aliases_pub {
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK

impl PrivAlias {
pub fn f(arg: Priv) {} //~ ERROR private type in public interface
pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING hard error
}
// This doesn't even parse
// impl <Priv as PrivTr>::AssocAlias {
// pub fn f(arg: Priv) {} // ERROR private type in public interface
// pub fn f(arg: Priv) {} // ERROR private type `aliases_pub::Priv` in public interface
// }
impl PrivUseAliasTr for PrivUseAlias {
type Check = Priv; //~ ERROR private type in public interface
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING hard error
}
impl PrivUseAliasTr for PrivAlias {
type Check = Priv; //~ ERROR private type in public interface
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING hard error
}
impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
type Check = Priv; //~ ERROR private type in public interface
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING hard error
}
}
Expand All @@ -251,11 +258,13 @@ mod aliases_priv {
type AssocAlias = Priv3;
}

pub trait Tr1: PrivUseAliasTr {} //~ ERROR private trait in public interface
//~^ WARNING hard error
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ ERROR private trait in public interface
//~^ ERROR private type in public interface
pub trait Tr1: PrivUseAliasTr {}
//~^ ERROR private trait `aliases_priv::PrivTr1` in public interface
//~| WARNING hard error
pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
//~^ ERROR private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface
//~| WARNING hard error
//~| ERROR private type `aliases_priv::Priv2` in public interface
//~| WARNING hard error

impl PrivUseAlias {
Expand Down
Loading

0 comments on commit 548e681

Please sign in to comment.