Skip to content

Commit aedf7ae

Browse files
authored
Merge pull request #1133 from Speedy-Consoles/master
Clarify pub(restricted) example a bit
2 parents 73456de + 5d1df00 commit aedf7ae

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/mod/visibility.md

+12-1
Original file line numberDiff line numberDiff 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
```

0 commit comments

Comments
 (0)