diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 608558ac2bdb9..ea20d2b423861 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -852,8 +852,12 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { ty::ImplContainer(_) => { self.check_static_method(span, method_def_id, name) } - // Trait methods are always accessible if the trait is in scope. - ty::TraitContainer(_) => {} + // 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")); + } } } } diff --git a/src/test/run-pass/issue-16264.rs b/src/test/compile-fail/trait-not-accessible.rs similarity index 68% rename from src/test/run-pass/issue-16264.rs rename to src/test/compile-fail/trait-not-accessible.rs index 67701de638693..21668fcfeae71 100644 --- a/src/test/run-pass/issue-16264.rs +++ b/src/test/compile-fail/trait-not-accessible.rs @@ -8,20 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use outer::Foo; +mod m { + trait Priv { + fn f(&self) {} + } + impl Priv for super::S {} + pub trait Pub: Priv {} +} -mod outer { - pub use self::inner::Foo; +struct S; +impl m::Pub for S {} - mod inner { - pub trait Foo { - fn bar(&self) {} - } - impl Foo for i32 {} - } +fn g(arg: T) { + arg.f(); //~ ERROR: source trait is private } fn main() { - let x: i32 = 0; - x.bar(); + g(S); }