From d908ff1759bf27a8a8a99f113a246b8abc61f425 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 26 Feb 2016 20:31:00 +0000 Subject: [PATCH] Don't treat associated types specially in `def_privacy` Improve trait privacy error message --- src/librustc_privacy/lib.rs | 18 ++++++------------ src/test/compile-fail/trait-not-accessible.rs | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 226539b8e804a..214ac81ee5092 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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, @@ -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)); } } } diff --git a/src/test/compile-fail/trait-not-accessible.rs b/src/test/compile-fail/trait-not-accessible.rs index 21668fcfeae71..5feef0a24eb0e 100644 --- a/src/test/compile-fail/trait-not-accessible.rs +++ b/src/test/compile-fail/trait-not-accessible.rs @@ -20,7 +20,7 @@ struct S; impl m::Pub for S {} fn g(arg: T) { - arg.f(); //~ ERROR: source trait is private + arg.f(); //~ ERROR: source trait `m::Priv` is private } fn main() {