Skip to content

Commit

Permalink
privacy: Mark everything in a header of a reachable impl as reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 5, 2019
1 parent 67713f5 commit 9503c56
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
// Visit everything except for private impl items.
hir::ItemKind::Impl(.., ref impl_item_refs) => {
if item_level.is_some() {
self.reach(item.id, item_level).generics().predicates();
self.reach(item.id, item_level).generics().predicates().ty().trait_ref();

for impl_item_ref in impl_item_refs {
let impl_item_level = self.get(impl_item_ref.id.node_id);
Expand Down Expand Up @@ -711,6 +711,13 @@ impl<'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'_, 'a, 'tcx> {
self.visit(self.ev.tcx.type_of(self.item_def_id));
self
}

fn trait_ref(&mut self) -> &mut Self {
if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) {
self.visit_trait(trait_ref);
}
self
}
}

impl<'a, 'tcx> DefIdVisitor<'a, 'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'a, 'tcx> {
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/privacy/auxiliary/issue-57264-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod inner {
pub struct PubUnnameable;

impl PubUnnameable {
pub fn pub_method(self) {}
}
}

pub trait PubTraitWithSingleImplementor {}
impl PubTraitWithSingleImplementor for Option<inner::PubUnnameable> {}
8 changes: 8 additions & 0 deletions src/test/ui/privacy/issue-57264-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-pass
// aux-build:issue-57264-1.rs

extern crate issue_57264_1;

fn main() {
issue_57264_1::Pub::pub_method();
}
10 changes: 10 additions & 0 deletions src/test/ui/privacy/issue-57264-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// compile-pass
// aux-build:issue-57264-2.rs

extern crate issue_57264_2;

fn infer<T: issue_57264_2::PubTraitWithSingleImplementor>(arg: T) -> T { arg }

fn main() {
infer(None).unwrap().pub_method();
}
8 changes: 0 additions & 8 deletions src/test/ui/privacy/issue-57264.rs

This file was deleted.

0 comments on commit 9503c56

Please sign in to comment.