Skip to content

Commit 4112aef

Browse files
authored
Rollup merge of rust-lang#57556 - petrochenkov:privexist, r=arielb1
privacy: Fix private-in-public check for existential types Fixes rust-lang#53546 (regression from rust-lang#56878) r? @arielb1
2 parents 0b7d8f9 + f8028b0 commit 4112aef

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/librustc_privacy/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod diagnostics;
4848
/// Default type visitor (`TypeVisitor`) does most of the job, but it has some shortcomings.
4949
/// First, it doesn't have overridable `fn visit_trait_ref`, so we have to catch trait def-ids
5050
/// manually. Second, it doesn't visit some type components like signatures of fn types, or traits
51-
/// in `impl Trait`, see individual commits in `DefIdVisitorSkeleton::visit_ty`.
51+
/// in `impl Trait`, see individual comments in `DefIdVisitorSkeleton::visit_ty`.
5252
trait DefIdVisitor<'a, 'tcx: 'a> {
5353
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
5454
fn shallow(&self) -> bool { false }
@@ -1579,10 +1579,15 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
15791579
// No subitems.
15801580
hir::ItemKind::GlobalAsm(..) => {}
15811581
// Subitems of these items have inherited publicity.
1582-
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) |
1583-
hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => {
1582+
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) |
1583+
hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => {
15841584
self.check(item.id, item_visibility).generics().predicates().ty();
15851585
}
1586+
hir::ItemKind::Existential(..) => {
1587+
// `ty()` for existential types is the underlying type,
1588+
// it's not a part of interface, so we skip it.
1589+
self.check(item.id, item_visibility).generics().predicates();
1590+
}
15861591
hir::ItemKind::Trait(.., ref trait_item_refs) => {
15871592
self.check(item.id, item_visibility).generics().predicates();
15881593

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-pass
2+
3+
#![feature(existential_type)]
4+
#![deny(private_in_public)]
5+
6+
pub existential type Pub: Default;
7+
8+
#[derive(Default)]
9+
struct Priv;
10+
11+
fn check() -> Pub {
12+
Priv
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)