Skip to content

Commit

Permalink
Don't treat associated types specially in def_privacy
Browse files Browse the repository at this point in the history
Improve trait privacy error message
  • Loading branch information
jseyfried committed Mar 4, 2016
1 parent 32f251c commit d908ff1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// decision solely based on the privacy of the method
// invocation.
Some(ast_map::NodeImplItem(ii)) => {
match ii.node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Method(..) => {
let imp = self.tcx.map.get_parent_did(node_id);
match self.tcx.impl_trait_ref(imp) {
Some(..) => hir::Public,
_ => ii.vis
}
}
hir::ImplItemKind::Type(_) => hir::Public,
let imp = self.tcx.map.get_parent_did(node_id);
match self.tcx.impl_trait_ref(imp) {
Some(..) => hir::Public,
_ => ii.vis,
}
}
Some(ast_map::NodeTraitItem(_)) => hir::Public,
Expand Down Expand Up @@ -804,8 +798,8 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// Trait methods are always all public. The only controlling factor
// is whether the trait itself is accessible or not.
ty::TraitContainer(trait_def_id) => {
self.report_error(self.ensure_public(span, trait_def_id,
None, "source trait"));
let msg = format!("source trait `{}`", self.tcx.item_path_str(trait_def_id));
self.report_error(self.ensure_public(span, trait_def_id, None, &msg));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/trait-not-accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct S;
impl m::Pub for S {}

fn g<T: m::Pub>(arg: T) {
arg.f(); //~ ERROR: source trait is private
arg.f(); //~ ERROR: source trait `m::Priv` is private
}

fn main() {
Expand Down

0 comments on commit d908ff1

Please sign in to comment.