]> git.lizzy.rs Git - rust.git/commitdiff
privacy: Fix private-in-public check for existential types
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 12 Jan 2019 21:41:11 +0000 (00:41 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 12 Jan 2019 21:41:11 +0000 (00:41 +0300)
src/librustc_privacy/lib.rs
src/test/ui/privacy/private-in-public-existential.rs [new file with mode: 0644]

index 5015ed027cc3c69ca26e87950e6d1522ffba57c8..4890369e13f2022975efea48ada74c49e40d473c 100644 (file)
@@ -48,7 +48,7 @@
 /// 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 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
             // 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();
 
diff --git a/src/test/ui/privacy/private-in-public-existential.rs b/src/test/ui/privacy/private-in-public-existential.rs
new file mode 100644 (file)
index 0000000..95658f4
--- /dev/null
@@ -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() {}