From ec72961e710a004c51550a500aacec572ee02983 Mon Sep 17 00:00:00 2001 From: Speedy Consoles Date: Thu, 20 Dec 2018 17:25:20 +0100 Subject: [PATCH] Clarify pub(restricted) example a bit --- src/mod/visibility.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mod/visibility.md b/src/mod/visibility.md index 6345630108..8e952fe48a 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 } -``` \ No newline at end of file +```