-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary trait accessibility check. #28504
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Not sure what the behavior should be if the trait has a private supertrait. |
I don't think this affects anything in that regard. It's already possible to reexport traits that depend on private supertraits anyway, e.g.: pub use inner::Bar;
mod inner {
trait Foo {
fn foo(&self) { println!("foo"); }
}
pub trait Bar: Foo {
fn bar(&self) { println!("bar"); }
}
impl Foo for i32 {}
impl Bar for i32 {}
}
fn main() {
//0i32.foo(); // Can't call this
0i32.bar();
} |
Ok, I thought you could call By the way, you can call foo through |
Nope, still gives the same error as on playpen:
This also still works. |
Ok, I'll report separate bugs for the |
It's been awhile since I've poked around the privacy-related code, but this looks good to me. To me it makes sense that the method call will only be resolved if the trait is already in scope, and because the import of the trait already had the privacy check run on it and verified then we don't have private trait methods so this is fine to let through. That being said I'd like a second set of eyes on this, so: r? @nrc |
Does this still give an error? mod foo {
trait Bar {
fn baz() {}
}
impl Bar for i32 {}
}
fn main() {
<i32 as ::foo::Bar>::baz(); //~ERROR method `baz` is inaccessible
} I assume that at the least the error message changes (to something about no impl for |
Added a cfail test. The error is exactly the same as on latest stable/beta/nightly:
|
@bors: r+ |
📌 Commit b3e1aca has been approved by |
Hmm, there's a regression in current nightly (it may be intentional though):
I guess it was caused by this patch? |
@petrochenkov That behavior is |
Since all regressions should be tracked, do we need an issue for that? cc @brson |
Thanks for the sharp eyes @petrochenkov! I've opened a PR to revert: #29325 |
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
…tsakis This PR allows using methods from traits that are visible but are defined in an inaccessible module (fixes #18241). For example, ```rust mod foo { pub use foo::bar::Tr; mod bar { // This module is inaccessible from `g` pub trait Tr { fn f(&self) {} } } } fn g<T: foo::Tr>(t: T) { t.f(); // Currently, this is a privacy error even though `foo::Tr` is visible } ``` After this PR, it will continue to be a privacy error to use a method from a trait that is not visible. This can happen when a public trait inherits from a private trait (in violation of the `public_in_private` lint) -- see @petrochenkov's example in #28504. r? @nikomatsakis
Fixes #16264 / #18241.
As far as I can tell, it should be impossible for a trait to be inaccessible if it's in scope, so this check is unnecessary. Are there any cases where this check is actually needed?