File tree Expand file tree Collapse file tree 1 file changed +46
-1
lines changed Expand file tree Collapse file tree 1 file changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -432,7 +432,7 @@ operators](#binary-operator-expressions), or [keywords](#keywords).
432
432
## Paths
433
433
434
434
~~~~ {.notrust .ebnf .gram}
435
- expr_path : ident [ "::" expr_path_tail ] + ;
435
+ expr_path : [ "::" ] ident [ "::" expr_path_tail ] + ;
436
436
expr_path_tail : '<' type_expr [ ',' type_expr ] + '>'
437
437
| expr_path ;
438
438
@@ -475,6 +475,51 @@ let x = id::<int>(10); // Type arguments used in a call expression
475
475
# }
476
476
~~~~
477
477
478
+ Paths can be denoted with various leading qualifiers to change the meaning of
479
+ how it is resolved:
480
+
481
+ * Paths starting with ` :: ` are considered to be global paths where the
482
+ components of the path start being resolved from the crate root. Each
483
+ identifier in the path must resolve to an item.
484
+
485
+ ``` rust
486
+ mod a {
487
+ pub fn foo () {}
488
+ }
489
+ mod b {
490
+ pub fn foo () {
491
+ :: a :: foo (); // call a's foo function
492
+ }
493
+ }
494
+ # fn main () {}
495
+ ```
496
+
497
+ * Paths starting with the keyword ` super ` begin resolution relative to the
498
+ parent module. Each further identifier must resolve to an item
499
+
500
+ ``` rust
501
+ mod a {
502
+ pub fn foo () {}
503
+ }
504
+ mod b {
505
+ pub fn foo () {
506
+ super :: a :: foo (); // call a's foo function
507
+ }
508
+ }
509
+ # fn main () {}
510
+ ```
511
+
512
+ * Paths starting with the keyword ` self ` begin resolution relative to the
513
+ current module. Each further identifier must resolve to an item.
514
+
515
+ ``` rust
516
+ fn foo () {}
517
+ fn bar () {
518
+ self :: foo ();
519
+ }
520
+ # fn main () {}
521
+ ```
522
+
478
523
# Syntax extensions
479
524
480
525
A number of minor features of Rust are not central enough to have their own
You can’t perform that action at this time.
0 commit comments