File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -851,6 +851,38 @@ In this example, the module `quux` re-exports all of the public names defined in
851
851
852
852
Also note that the paths contained in ` use ` items are relative to the crate root.
853
853
So, in the previous example, the ` use ` refers to ` quux::foo::* ` , and not simply to ` foo::* ` .
854
+ This also means that top-level module declarations should be at the crate root if direct usage
855
+ of the declared modules within ` use ` items is desired. It is also possible to use ` self ` and ` super `
856
+ at the beginning of a ` use ` item to refer to the current and direct parent modules respectively.
857
+ All rules regarding accessing declared modules in ` use ` declarations applies to both module declarations
858
+ and ` extern mod ` declarations.
859
+
860
+ An example of what will and will not work for ` use ` items:
861
+ ~~~~
862
+ # #[allow(unused_imports)];
863
+ use foo::extra; // good: foo is at the root of the crate
864
+ use foo::baz::foobaz; // good: foo is at the root of the crate
865
+
866
+ mod foo {
867
+ extern mod extra;
868
+
869
+ use foo::extra::list; // good: foo is at crate root
870
+ // use extra::*; // bad: extra is not at the crate root
871
+ use self::baz::foobaz; // good: self refers to module 'foo'
872
+ use foo::bar::foobar; // good: foo is at crate root
873
+
874
+ pub mod bar {
875
+ pub fn foobar() { }
876
+ }
877
+
878
+ pub mod baz {
879
+ use super::bar::foobar; // good: super refers to module 'foo'
880
+ pub fn foobaz() { }
881
+ }
882
+ }
883
+
884
+ fn main() {}
885
+ ~~~~
854
886
855
887
### Functions
856
888
You can’t perform that action at this time.
0 commit comments