Skip to content

Commit bc927a6

Browse files
committed
Explain super in the crates guide.
Fixes #19808
1 parent ead9ab8 commit bc927a6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/doc/trpl/crates-and-modules.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@ Here we have a `pub use` for each function we want to bring into the
555555
`japanese` scope. We could alternatively use the wildcard syntax to include
556556
everything from `greetings` into the current scope: `pub use self::greetings::*`.
557557
558+
What about the `self`? Well, by default, `use` declarations are absolute paths,
559+
starting from your crate root. `self` makes that path relative to your current
560+
place in the hierarchy instead. There's one more special form of `use`: you can
561+
`use super::` to reach one level up the tree from your current location. Some
562+
people like to think of `self` as `.` and `super` as `..`, from many shells'
563+
display for the current directory and the parent directory.
564+
558565
Also, note that we `pub use`d before we declared our `mod`s. Rust requires that
559566
`use` declarations go first.
560567

0 commit comments

Comments
 (0)