-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Labels
A-visibilityArea: Visibility / privacyArea: Visibility / privacy
Description
mod foo {
pub struct Foo;
impl Foo {
pub fn normal(&self) {
self.private();
self.public();
}
}
mod bar {
impl super::Foo {
fn private(&self) {}
pub fn public(&self) { self.private() }
}
}
}
fn main() {
foo::Foo.normal();
foo::Foo.private();
foo::Foo.public();
}Compilation fails with
<anon>:5:13: 5:27 error: method `private` is private
<anon>:5 self.private();
^~~~~~~~~~~~~~
<anon>:19:5: 19:23 error: method `private` is private
<anon>:19 foo::Foo.private();
^~~~~~~~~~~~~~~~~~
(Removing those two .private calls compiles fine.)
This is inconsistent because:
privateis only accessible insidebar, i.e. being private means it is being scoped with the modulepublicis accessible everywhere despitebarbeing private (if it were a freestanding function, one could only callfoo::bar::publicinsidefoo, not insidemain); i.e. it appears to be being scoped with the type
I would expect both pub and non-pub methods to have the same scoping either both with the type (so foo and any descendants can call private, as well as main calling public), or both with the module (so main cannot call public).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-visibilityArea: Visibility / privacyArea: Visibility / privacy