Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Document flavorful variations of paths #13388

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;

Expand Down Expand Up @@ -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
Expand Down