diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-07 14:34:56 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 00:03:11 -0700 |
| commit | c83afb9719ad6e2ae7d819b8096524e1147c4065 (patch) | |
| tree | 12bd44fdc7cf5bfd0c59caca928d2ef3c9554a29 | |
| parent | bc234ae1307f6c1ff72782a82b8222691bf67525 (diff) | |
doc: Document flavorful variations of paths
Closes #4293
| -rw-r--r-- | src/doc/rust.md | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/doc/rust.md b/src/doc/rust.md index afb21a19965..886c95b2c75 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -432,7 +432,7 @@ operators](#binary-operator-expressions), or [keywords](#keywords). ## Paths ~~~~ {.notrust .ebnf .gram} -expr_path : ident [ "::" expr_path_tail ] + ; +expr_path : [ "::" ] ident [ "::" expr_path_tail ] + ; expr_path_tail : '<' type_expr [ ',' type_expr ] + '>' | expr_path ; @@ -475,6 +475,51 @@ let x = id::<int>(10); // Type arguments used in a call expression # } ~~~~ +Paths can be denoted with various leading qualifiers to change the meaning of +how it is resolved: + +* Paths starting with `::` are considered to be global paths where the + components of the path start being resolved from the crate root. Each + identifier in the path must resolve to an item. + + ```rust + mod a { + pub fn foo() {} + } + mod b { + pub fn foo() { + ::a::foo(); // call a's foo function + } + } + # fn main() {} + ``` + +* Paths starting with the keyword `super` begin resolution relative to the + parent module. Each further identifier must resolve to an item + + ```rust + mod a { + pub fn foo() {} + } + mod b { + pub fn foo() { + super::a::foo(); // call a's foo function + } + } + # fn main() {} + ``` + +* Paths starting with the keyword `self` begin resolution relative to the + current module. Each further identifier must resolve to an item. + + ```rust + fn foo() {} + fn bar() { + self::foo(); + } + # fn main() {} + ``` + # Syntax extensions A number of minor features of Rust are not central enough to have their own |
