Skip to content

Commit fbf3628

Browse files
committed
Remove description of export, briefly describe pub use.
1 parent 385c4df commit fbf3628

File tree

1 file changed

+14
-86
lines changed

1 file changed

+14
-86
lines changed

doc/rust.md

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,8 @@ link_attrs : link_attr [ ',' link_attrs ] + ;
783783
link_attr : ident '=' literal ;
784784
~~~~~~~~
785785

786-
An _extern mod declaration_ specifies a dependency on an external crate. The
787-
external crate is then imported into the declaring scope as the `ident`
788-
provided in the `extern_mod_decl`.
786+
An _extern mod declaration_ specifies a dependency on an external crate.
787+
The external crate is then bound into the declaring scope as the `ident` provided in the `extern_mod_decl`.
789788

790789
The external crate is resolved to a specific `soname` at compile time, and a
791790
runtime linkage requirement to that `soname` is passed to the linker for
@@ -825,16 +824,16 @@ linkage-dependency with external crates. Linkage dependencies are
825824
independently declared with
826825
[`extern mod` declarations](#extern-mod-declarations).
827826

828-
Imports support a number of "convenience" notations:
827+
Use declarations support a number of "convenience" notations:
829828

830-
* Importing as a different name than the imported name, using the
829+
* Rebinding the target name as a new local name, using the
831830
syntax `use x = p::q::r;`.
832-
* Importing a list of paths differing only in final element, using
833-
the glob-like brace syntax `use a::b::{c,d,e,f};`
834-
* Importing all paths matching a given prefix, using the glob-like
835-
asterisk syntax `use a::b::*;`
831+
* Simultaneously binding a list of paths differing only in final element,
832+
using the glob-like brace syntax `use a::b::{c,d,e,f};`
833+
* Binding all paths matching a given prefix,
834+
using the glob-like asterisk syntax `use a::b::*;`
836835

837-
An example of imports:
836+
An example of `use` declarations:
838837

839838
~~~~
840839
use foo = core::info;
@@ -855,82 +854,11 @@ fn main() {
855854
}
856855
~~~~
857856

858-
##### Export declarations
859-
860-
~~~~~~~~ {.ebnf .gram}
861-
export_decl : "export" ident [ ',' ident ] *
862-
| "export" ident "::{}"
863-
| "export" ident '{' ident [ ',' ident ] * '}' ;
864-
~~~~~~~~
865-
866-
An _export declaration_ restricts the set of local names within a module that
867-
can be accessed from code outside the module. By default, all _local items_ in
868-
a module are exported; imported paths are not automatically re-exported by
869-
default. If a module contains an explicit `export` declaration, this
870-
declaration replaces the default export with the export specified.
871-
872-
An example of an export:
873-
874-
~~~~~~~~
875-
pub mod foo {
876-
#[legacy_exports];
877-
export primary;
878-
879-
fn primary() {
880-
helper(1, 2);
881-
helper(3, 4);
882-
}
883-
884-
fn helper(x: int, y: int) {
885-
...
886-
}
887-
}
888-
889-
fn main() {
890-
foo::primary(); // Will compile.
891-
}
892-
~~~~~~~~
893-
894-
If, instead of calling `foo::primary` in main, you were to call `foo::helper`
895-
then it would fail to compile:
896-
897-
~~~~~~~~{.ignore}
898-
foo::helper(2,3) // ERROR: will not compile.
899-
~~~~~~~~
900-
901-
Multiple names may be exported from a single export declaration:
902-
903-
~~~~~~~~
904-
mod foo {
905-
export primary, secondary;
906-
907-
fn primary() {
908-
helper(1, 2);
909-
helper(3, 4);
910-
}
911-
912-
fn secondary() {
913-
...
914-
}
915-
916-
fn helper(x: int, y: int) {
917-
...
918-
}
919-
}
920-
~~~~~~~~
921-
922-
When exporting the name of an `enum` type `t`, by default, the module does
923-
*not* implicitly export any of `t`'s constructors. For example:
924-
925-
~~~~~~~~
926-
mod foo {
927-
export t;
928-
929-
enum t {a, b, c}
930-
}
931-
~~~~~~~~
932-
933-
Here, `foo` imports `t`, but not `a`, `b`, and `c`.
857+
Like items, `use` declarations are private to the containing module, by default.
858+
Also like items, a `use` declaration can be public, if qualified by the `pub` keyword.
859+
A public `use` declaration can therefore be used to _redirect_ some public name to a different target definition,
860+
even a definition with a private canonical path, inside a different module.
861+
If a sequence of such redirections form a cycle or cannot be unambiguously resolved, they represent a compile-time error.
934862

935863
### Functions
936864

0 commit comments

Comments
 (0)