privacy: Fix private-in-public check for existential types

This commit is contained in:
Vadim Petrochenkov 2019-01-13 00:41:11 +03:00
parent d6525ef539
commit f8028b0b6c
2 changed files with 23 additions and 3 deletions

View file

@ -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 }
@ -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();

View file

@ -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() {}