Skip to content

Commit

Permalink
privacy: Substitute type aliases in private-in-public checker
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Aug 10, 2016
1 parent 1f2ae38 commit b7db9e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/librustc_privacy/lib.rs
Expand Up @@ -873,12 +873,6 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
// Return the visibility of the type alias's least visible component type when substituted
fn substituted_alias_visibility(&self, item: &hir::Item, path: &hir::Path)
-> Option<ty::Visibility> {
// We substitute type aliases only when determining impl publicity
// FIXME: This will probably change and all type aliases will be substituted,
// requires an amendment to RFC 136.
if self.required_visibility != ty::Visibility::PrivateExternal {
return None;
}
// Type alias is considered public if the aliased type is
// public, even if the type alias itself is private. So, something
// like `type A = u8; pub fn f() -> A {...}` doesn't cause an error.
Expand Down
9 changes: 6 additions & 3 deletions src/test/compile-fail/private-in-public-warn.rs
Expand Up @@ -205,11 +205,10 @@ mod aliases_pub {
}

pub fn f1(arg: PrivUseAlias) {} // OK
pub fn f2(arg: PrivAlias) {} // OK

pub trait Tr1: PrivUseAliasTr {} // OK
// This should be OK, if type aliases are substituted
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private type in public interface
//~^ WARNING hard error
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK

impl PrivAlias {
pub fn f(arg: Priv) {} //~ WARN private type in public interface
Expand Down Expand Up @@ -246,6 +245,8 @@ mod aliases_priv {
use self::Priv1 as PrivUseAlias;
use self::PrivTr1 as PrivUseAliasTr;
type PrivAlias = Priv2;
//~^ WARN private type in public interface
//~| WARNING hard error
trait PrivTr {
type AssocAlias;
}
Expand Down Expand Up @@ -285,6 +286,8 @@ mod aliases_params {
struct Priv;
type PrivAliasGeneric<T = Priv> = T;
type Result<T> = ::std::result::Result<T, Priv>;

pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
}

#[rustc_error]
Expand Down
4 changes: 0 additions & 4 deletions src/test/compile-fail/private-in-public.rs
Expand Up @@ -105,8 +105,6 @@ mod aliases_pub {
}
impl PrivTr for Priv {}

// This should be OK, if type aliases are substituted
pub fn f2(arg: PrivAlias) {} //~ ERROR private type in public interface
// This should be OK, but associated type aliases are not substituted yet
pub fn f3(arg: <Priv as PrivTr>::AssocAlias) {} //~ ERROR private type in public interface

Expand Down Expand Up @@ -143,8 +141,6 @@ mod aliases_params {
type PrivAliasGeneric<T = Priv> = T;
type Result<T> = ::std::result::Result<T, Priv>;

// This should be OK, if type aliases are substituted
pub fn f1(arg: PrivAliasGeneric<u8>) {} //~ ERROR private type in public interface
pub fn f2(arg: PrivAliasGeneric) {} //~ ERROR private type in public interface
pub fn f3(arg: Result<u8>) {} //~ ERROR private type in public interface
}
Expand Down

0 comments on commit b7db9e8

Please sign in to comment.