diff --git a/src/mod/visibility.md b/src/mod/visibility.md index 5f436f57da..46c0b6abd1 100644 --- a/src/mod/visibility.md +++ b/src/mod/visibility.md @@ -43,7 +43,7 @@ mod my_mod { } // Functions declared using `pub(self)` syntax are only visible within - // the current module + // the current module, which is the same as leaving them private pub(self) fn public_function_in_nested() { println!("called `my_mod::nested::public_function_in_nested"); } @@ -73,6 +73,13 @@ mod my_mod { pub fn function() { println!("called `my_mod::private_nested::function()`"); } + + // Private parent items will still restrict the visibility of a child item, + // even if it is declared as visible within a bigger scope. + #[allow(dead_code)] + pub(crate) fn restricted_function() { + println!("called `my_mod::private_nested::restricted_function()`"); + } } } @@ -113,5 +120,9 @@ fn main() { // Error! `private_nested` is a private module //my_mod::private_nested::function(); // TODO ^ Try uncommenting this line + + // Error! `private_nested` is a private module + //my_mod::private_nested::restricted_function(); + // TODO ^ Try uncommenting this line } ```