Skip to content

Commit

Permalink
Clarify use_decl module resolution docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonson committed Aug 23, 2013
1 parent f858452 commit 35ec01a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions doc/rust.md
Expand Up @@ -851,6 +851,38 @@ In this example, the module `quux` re-exports all of the public names defined in

Also note that the paths contained in `use` items are relative to the crate root.
So, in the previous example, the `use` refers to `quux::foo::*`, and not simply to `foo::*`.
This also means that top-level module declarations should be at the crate root if direct usage
of the declared modules within `use` items is desired. It is also possible to use `self` and `super`
at the beginning of a `use` item to refer to the current and direct parent modules respectively.
All rules regarding accessing declared modules in `use` declarations applies to both module declarations
and `extern mod` declarations.

An example of what will and will not work for `use` items:
~~~~
# #[allow(unused_imports)];
use foo::extra; // good: foo is at the root of the crate
use foo::baz::foobaz; // good: foo is at the root of the crate
mod foo {
extern mod extra;
use foo::extra::list; // good: foo is at crate root
// use extra::*; // bad: extra is not at the crate root
use self::baz::foobaz; // good: self refers to module 'foo'
use foo::bar::foobar; // good: foo is at crate root
pub mod bar {
pub fn foobar() { }
}
pub mod baz {
use super::bar::foobar; // good: super refers to module 'foo'
pub fn foobaz() { }
}
}
fn main() {}
~~~~

### Functions

Expand Down

5 comments on commit 35ec01a

@bors
Copy link
Contributor

@bors bors commented on 35ec01a Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brandonson@35ec01a

@bors
Copy link
Contributor

@bors bors commented on 35ec01a Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging singingboyo/rust/use-decl-doc = 35ec01a into auto

@bors
Copy link
Contributor

@bors bors commented on 35ec01a Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singingboyo/rust/use-decl-doc = 35ec01a merged ok, testing candidate = 6f70377

@bors
Copy link
Contributor

@bors bors commented on 35ec01a Aug 23, 2013

@bors
Copy link
Contributor

@bors bors commented on 35ec01a Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6f70377

Please sign in to comment.