Skip to content

Commit a09246a

Browse files
committed
Approximate type aliases as public when determining impl publicity
1 parent f8ae31f commit a09246a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/librustc_privacy/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,21 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
11281128
def::DefPrimTy(..) | def::DefSelfTy(..) | def::DefTyParam(..) => {
11291129
// Public
11301130
}
1131+
def::DefAssociatedTy(..) if self.is_quiet => {
1132+
// Conservatively approximate the whole type alias as public without
1133+
// recursing into its components when determining impl publicity.
1134+
return
1135+
}
11311136
def::DefStruct(def_id) | def::DefTy(def_id, _) |
11321137
def::DefTrait(def_id) | def::DefAssociatedTy(def_id, _) => {
11331138
// Non-local means public, local needs to be checked
11341139
if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
11351140
if let Some(ast_map::NodeItem(ref item)) = self.tcx.map.find(node_id) {
1141+
if let (&hir::ItemTy(..), true) = (&item.node, self.is_quiet) {
1142+
// Conservatively approximate the whole type alias as public without
1143+
// recursing into its components when determining impl publicity.
1144+
return
1145+
}
11361146
if item.vis != hir::Public {
11371147
if !self.is_quiet {
11381148
span_err!(self.tcx.sess, ty.span, E0446,

src/test/compile-fail/lint-visible-private-types.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,22 @@ impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in public interface
121121
ParamTrait<T> for Public<i8> {
122122
fn foo() -> T { panic!() }
123123
}
124+
125+
type PrivAlias = Public<i8>;
126+
127+
trait PrivTrait2 {
128+
type Alias;
129+
}
130+
impl PrivTrait2 for Private<isize> {
131+
type Alias = Public<u8>;
132+
}
133+
134+
impl PubTrait for PrivAlias {
135+
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
136+
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in public interface
137+
}
138+
139+
impl PubTrait for <Private<isize> as PrivTrait2>::Alias {
140+
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
141+
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in public interface
142+
}

0 commit comments

Comments
 (0)