@@ -145,14 +145,15 @@ expressions, types, etc.
145145## ` pub(in path) ` , ` pub(crate) ` , ` pub(super) ` , and ` pub(self) `
146146
147147In addition to public and private, Rust allows users to declare an item as
148- visible within a given scope. The rules for ` pub ` restrictions are as follows:
148+ visible only within a given scope. The rules for ` pub ` restrictions are as
149+ follows:
149150- ` pub(in path) ` makes an item visible within the provided ` path ` . ` path ` must
150151be a parent module of the item whose visibility is being declared.
151152- ` pub(crate) ` makes an item visible within the current crate.
152153- ` pub(super) ` makes an item visible to the parent module. This is equivalent
153154 to ` pub(in super) ` .
154155- ` pub(self) ` makes an item visible to the current module. This is equivalent
155- to ` pub(in self) ` .
156+ to ` pub(in self) ` or not using ` pub ` at all .
156157
157158> ** Edition Differences** : Starting with the 2018 edition, paths for
158159> ` pub(in path) ` must start with ` crate ` , ` self ` , or ` super ` . The 2015 edition
@@ -177,7 +178,8 @@ pub mod outer_mod {
177178 inner_mod_visible_fn ();
178179 }
179180
180- // This function is visible
181+ // This function is visible only within `inner_mod`,
182+ // which is the same as leaving it private.
181183 pub (self ) fn inner_mod_visible_fn () {}
182184 }
183185 pub fn foo () {
@@ -209,6 +211,11 @@ fn bar() {
209211fn main () { bar () }
210212```
211213
214+ > ** Note:** This syntax only adds another restriction to the visibility of an
215+ > item. It does not guarantee that the item is visible within all parts of the
216+ > specified scope. To access an item, all of its parent items up to the
217+ > current scope must still be visible as well.
218+
212219## Re-exporting and Visibility
213220
214221Rust allows publicly re-exporting items through a ` pub use ` directive. Because
0 commit comments