Skip to content

Commit 95fb8d1

Browse files
committed
Auto merge of #29325 - alexcrichton:revert-trait-accessibility, r=nrc
These commits revert #28504 and add a regression test pointed out by @petrochenkov, it's not immediately clear with the regression that the accessibility check should be removed, so for now preserve the behavior on stable by default. r? @nrc
2 parents 05eb81a + 31fa916 commit 95fb8d1

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/librustc_privacy/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,12 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
852852
ty::ImplContainer(_) => {
853853
self.check_static_method(span, method_def_id, name)
854854
}
855-
// Trait methods are always accessible if the trait is in scope.
856-
ty::TraitContainer(_) => {}
855+
// Trait methods are always all public. The only controlling factor
856+
// is whether the trait itself is accessible or not.
857+
ty::TraitContainer(trait_def_id) => {
858+
self.report_error(self.ensure_public(span, trait_def_id,
859+
None, "source trait"));
860+
}
857861
}
858862
}
859863
}

src/test/run-pass/issue-16264.rs renamed to src/test/compile-fail/trait-not-accessible.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use outer::Foo;
11+
mod m {
12+
trait Priv {
13+
fn f(&self) {}
14+
}
15+
impl Priv for super::S {}
16+
pub trait Pub: Priv {}
17+
}
1218

13-
mod outer {
14-
pub use self::inner::Foo;
19+
struct S;
20+
impl m::Pub for S {}
1521

16-
mod inner {
17-
pub trait Foo {
18-
fn bar(&self) {}
19-
}
20-
impl Foo for i32 {}
21-
}
22+
fn g<T: m::Pub>(arg: T) {
23+
arg.f(); //~ ERROR: source trait is private
2224
}
2325

2426
fn main() {
25-
let x: i32 = 0;
26-
x.bar();
27+
g(S);
2728
}

0 commit comments

Comments
 (0)