Skip to content

Commit

Permalink
privacy: Fix private-in-public check for existential types
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 12, 2019
1 parent d6525ef commit f8028b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/librustc_privacy/lib.rs
Expand Up @@ -48,7 +48,7 @@ mod diagnostics;
/// Default type visitor (`TypeVisitor`) does most of the job, but it has some shortcomings.
/// First, it doesn't have overridable `fn visit_trait_ref`, so we have to catch trait def-ids
/// manually. Second, it doesn't visit some type components like signatures of fn types, or traits
/// in `impl Trait`, see individual commits in `DefIdVisitorSkeleton::visit_ty`.
/// in `impl Trait`, see individual comments in `DefIdVisitorSkeleton::visit_ty`.
trait DefIdVisitor<'a, 'tcx: 'a> {
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
fn shallow(&self) -> bool { false }
Expand Down Expand Up @@ -1579,10 +1579,15 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
// No subitems.
hir::ItemKind::GlobalAsm(..) => {}
// Subitems of these items have inherited publicity.
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) |
hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => {
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) |
hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => {
self.check(item.id, item_visibility).generics().predicates().ty();
}
hir::ItemKind::Existential(..) => {
// `ty()` for existential types is the underlying type,
// it's not a part of interface, so we skip it.
self.check(item.id, item_visibility).generics().predicates();
}
hir::ItemKind::Trait(.., ref trait_item_refs) => {
self.check(item.id, item_visibility).generics().predicates();

Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/privacy/private-in-public-existential.rs
@@ -0,0 +1,15 @@
// compile-pass

#![feature(existential_type)]
#![deny(private_in_public)]

pub existential type Pub: Default;

#[derive(Default)]
struct Priv;

fn check() -> Pub {
Priv
}

fn main() {}

0 comments on commit f8028b0

Please sign in to comment.