Skip to content

Commit b7db9e8

Browse files
committed
privacy: Substitute type aliases in private-in-public checker
1 parent 1f2ae38 commit b7db9e8

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/librustc_privacy/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,6 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
873873
// Return the visibility of the type alias's least visible component type when substituted
874874
fn substituted_alias_visibility(&self, item: &hir::Item, path: &hir::Path)
875875
-> Option<ty::Visibility> {
876-
// We substitute type aliases only when determining impl publicity
877-
// FIXME: This will probably change and all type aliases will be substituted,
878-
// requires an amendment to RFC 136.
879-
if self.required_visibility != ty::Visibility::PrivateExternal {
880-
return None;
881-
}
882876
// Type alias is considered public if the aliased type is
883877
// public, even if the type alias itself is private. So, something
884878
// like `type A = u8; pub fn f() -> A {...}` doesn't cause an error.

src/test/compile-fail/private-in-public-warn.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ mod aliases_pub {
205205
}
206206

207207
pub fn f1(arg: PrivUseAlias) {} // OK
208+
pub fn f2(arg: PrivAlias) {} // OK
208209

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

214213
impl PrivAlias {
215214
pub fn f(arg: Priv) {} //~ WARN private type in public interface
@@ -246,6 +245,8 @@ mod aliases_priv {
246245
use self::Priv1 as PrivUseAlias;
247246
use self::PrivTr1 as PrivUseAliasTr;
248247
type PrivAlias = Priv2;
248+
//~^ WARN private type in public interface
249+
//~| WARNING hard error
249250
trait PrivTr {
250251
type AssocAlias;
251252
}
@@ -285,6 +286,8 @@ mod aliases_params {
285286
struct Priv;
286287
type PrivAliasGeneric<T = Priv> = T;
287288
type Result<T> = ::std::result::Result<T, Priv>;
289+
290+
pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
288291
}
289292

290293
#[rustc_error]

src/test/compile-fail/private-in-public.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ mod aliases_pub {
105105
}
106106
impl PrivTr for Priv {}
107107

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

@@ -143,8 +141,6 @@ mod aliases_params {
143141
type PrivAliasGeneric<T = Priv> = T;
144142
type Result<T> = ::std::result::Result<T, Priv>;
145143

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

0 commit comments

Comments
 (0)