Skip to content

Commit d908ff1

Browse files
committed
Don't treat associated types specially in def_privacy
Improve trait privacy error message
1 parent 32f251c commit d908ff1

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/librustc_privacy/lib.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
615615
// decision solely based on the privacy of the method
616616
// invocation.
617617
Some(ast_map::NodeImplItem(ii)) => {
618-
match ii.node {
619-
hir::ImplItemKind::Const(..) |
620-
hir::ImplItemKind::Method(..) => {
621-
let imp = self.tcx.map.get_parent_did(node_id);
622-
match self.tcx.impl_trait_ref(imp) {
623-
Some(..) => hir::Public,
624-
_ => ii.vis
625-
}
626-
}
627-
hir::ImplItemKind::Type(_) => hir::Public,
618+
let imp = self.tcx.map.get_parent_did(node_id);
619+
match self.tcx.impl_trait_ref(imp) {
620+
Some(..) => hir::Public,
621+
_ => ii.vis,
628622
}
629623
}
630624
Some(ast_map::NodeTraitItem(_)) => hir::Public,
@@ -804,8 +798,8 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
804798
// Trait methods are always all public. The only controlling factor
805799
// is whether the trait itself is accessible or not.
806800
ty::TraitContainer(trait_def_id) => {
807-
self.report_error(self.ensure_public(span, trait_def_id,
808-
None, "source trait"));
801+
let msg = format!("source trait `{}`", self.tcx.item_path_str(trait_def_id));
802+
self.report_error(self.ensure_public(span, trait_def_id, None, &msg));
809803
}
810804
}
811805
}

src/test/compile-fail/trait-not-accessible.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct S;
2020
impl m::Pub for S {}
2121

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

2626
fn main() {

0 commit comments

Comments
 (0)