-
Notifications
You must be signed in to change notification settings - Fork 13.4k
A private module can be used outside its containing module #31779
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Here is an example without an inherent impls: mod foo {
mod bar { // `bar` should only be visible inside `foo`
pub use baz;
}
}
pub mod baz {
fn f() {}
fn g() {
::foo::bar::baz::f(); //< yet this line compiles
}
} If |
A path Since Most of the time, the visibilities of these non- However, our approach in insufficient if this assumption does not hold, i.e. if a path has a non- We will need to either give the privacy checker more information than just the |
Having the information about the way in which a particular name was introduced (directly, or through a specific |
Definitely agree that it would a good for the rest of the compiler to know what item a path resolves to before following |
This can also allow access to a private trait: mod foo {
trait T { // This should be private to `foo`
type Assoc;
}
impl T for () {
type Assoc = super::S;
}
}
struct S;
impl S {
fn f() {}
}
fn main() {
<() as foo::T>::Assoc::f(); // but it can be used here
} |
|
I think this is more of a problem with the data (or lack thereof) that we are giving to |
Speaking of bugs in the privacy checker, do you think this should be a privacy error? mod foo {
mod bar {
pub trait Parent {
fn f(&self) {}
}
}
pub trait Child: bar::Parent {}
}
fn f<T: foo::Child>(t: T) {
t.f(); // Right now, this line causes an error that `Parent` is inaccessible since `bar` is private
} I don't think it should since the trait and method are |
That's a philosophical question! |
Oh, and |
Ok, that will make fixing #18241 easier. The fundamental problem is that the core primitive in Nameability only matters for paths and |
The only reason why this is not more of a problem right now is that the rest of |
I'm pretty sure #18241 can be fixed trivially by reapplying #28504, public traits can't inherit from private traits anymore, so the reason why #28504 was reverted is not actual now. |
Good point, but sometimes it's only a |
This PR privacy checks paths as they are resolved instead of in `librustc_privacy` (fixes #12334 and fixes #31779). This removes the need for the `LastPrivate` system introduced in PR #9735, the limitations of which cause #31779. This PR also reports privacy violations in paths to intra- and inter-crate items the same way -- it always reports the first inaccessible segment of the path. Since it fixes #31779, this is a [breaking-change]. For example, the following code would break: ```rust mod foo { pub use foo::bar::S; mod bar { // `bar` should be private to `foo` pub struct S; } } impl foo::S { fn f() {} } fn main() { foo::bar::S::f(); // This is now a privacy error } ``` r? @alexcrichton
Consider the following code:
The text was updated successfully, but these errors were encountered: