File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ mod my_mod {
4343 }
4444
4545 // Functions declared using `pub(self)` syntax are only visible within
46- // the current module
46+ // the current module, which is the same as leaving them private
4747 pub(self) fn public_function_in_nested() {
4848 println!("called `my_mod::nested::public_function_in_nested");
4949 }
@@ -73,6 +73,13 @@ mod my_mod {
7373 pub fn function() {
7474 println!("called `my_mod::private_nested::function()`");
7575 }
76+
77+ // Private parent items will still restrict the visibility of a child item,
78+ // even if it is declared as visible within a bigger scope.
79+ #[allow(dead_code)]
80+ pub(crate) fn restricted_function() {
81+ println!("called `my_mod::private_nested::restricted_function()`");
82+ }
7683 }
7784}
7885
@@ -113,5 +120,9 @@ fn main() {
113120 // Error! `private_nested` is a private module
114121 //my_mod::private_nested::function();
115122 // TODO ^ Try uncommenting this line
123+
124+ // Error! `private_nested` is a private module
125+ //my_mod::private_nested::restricted_function();
126+ // TODO ^ Try uncommenting this line
116127}
117128```
You can’t perform that action at this time.
0 commit comments