@@ -550,7 +550,7 @@ Additional specific influences can be seen from the following languages:
550
550
551
551
@menu
552
552
* Ref.Lex :: Lexical structure.
553
- * Ref.Path :: References to slots and items.
553
+ * Ref.Path :: References to items.
554
554
* Ref.Gram :: Grammar.
555
555
* Ref.Comp :: Compilation and component model.
556
556
* Ref.Mem :: Semantic model of memory.
@@ -977,69 +977,43 @@ The special symbols are:
977
977
@page
978
978
@node Ref.Path
979
979
@section Ref.Path
980
- @c * Ref.Path:: References to slots and items.
980
+ @c * Ref.Path:: References to items.
981
981
@cindex Names of items or slots
982
982
@cindex Path name
983
983
@cindex Type parameters
984
984
985
- A @dfn {path } is a ubiquitous syntactic form in Rust that deserves special
986
- attention. A path denotes a slot or an
987
- item. @xref {Ref.Mem.Slot }. @xref {Ref.Item }. Every slot and item in a Rust
988
- crate has a @emph {canonical path } that refers to it from the crate top-level,
989
- as well as a number of shorter @emph {relative paths } that may also denote it
990
- in inner scopes of the crate. There is no way to define a slot or item without
991
- a canonical path within its crate (with the exception of the crate's implicit
992
- top-level module). Paths have meaning only within a specific
993
- crate. @xref {Ref.Comp.Crate }.
985
+ A @dfn {path } is a sequence of one or more path components separated by a
986
+ namespace qualifier (@code {:: }). If a path consists of only one component, it
987
+ may refer to either an item or a slot in a local control
988
+ scope. @xref {Ref.Mem.Slot }. @xref {Ref.Item }. If a path has multiple
989
+ components, it refers to an item.
994
990
995
- Paths consist of period-separated components. In the simplest form, path
996
- components are identifiers. @xref {Ref.Lex.Ident }.
991
+ Every item has a @emph {canonical path } within its crate, but the path naming
992
+ an item is only meaningful within a given crate. There is no global namespace
993
+ across crates; an item's canonical path merely identifies it within the
994
+ crate. @xref {Ref.Comp.Crate }
995
+
996
+ Path components are usually identifiers. @xref {Ref.Lex.Ident }. The last
997
+ component of a path may also have trailing explicit type arguments.
997
998
998
999
Two examples of simple paths consisting of only identifier components:
999
1000
@example
1000
1001
x;
1001
- x.y.z;
1002
- @end example
1003
-
1004
- Paths fall into two important categories: @emph {names } and
1005
- @emph {lvals }.
1006
-
1007
- A @dfn {name } denotes an item, and is statically resolved to its
1008
- referent at compile time.
1009
-
1010
- An @dfn {lval } denotes a slot or some component of a value held within a slot,
1011
- and is statically resolved at compile time to a sequence of memory operations
1012
- and primitive (arithmetic) expressions that will be executed to load or store
1013
- the associated value, starting from the task stack frame, at run time.
1014
-
1015
- In some contexts, the Rust grammar accepts a general @emph {path }, but a
1016
- subsequent syntactic restriction requires the path to be an lval or a name. In
1017
- other words: in some contexts an lval is required (for example, on the left
1018
- hand side of the copy operator, @pxref {Ref.Expr.Copy }) and in other contexts a
1019
- name is required (for example, as a type parameter, @pxref {Ref.Item }). In no
1020
- case is the grammar made ambiguous by accepting a general path and restricting
1021
- allowed paths to names or lvals after parsing. These restrictions are noted in
1022
- the grammar. @xref {Ref.Gram }.
1023
-
1024
- A name component may include type parameters. Type parameters are denoted by
1025
- square brackets. Square brackets are used @emph {only } to denote type
1026
- parameters in Rust. If a name component includes a type parameter, the type
1027
- parameter must also resolve statically to a type in the environment of the
1028
- name. Type parameters are only part of the names of items. @xref {Ref.Item }.
1029
-
1030
- An example of a name with type parameters:
1031
- @example
1032
- m.map[int,str];
1002
+ x::y::z;
1033
1003
@end example
1034
1004
1035
- An lval component may include an indexing operator. Index operators are
1036
- enclosed in parentheses and can include any integral expression. Indexing
1037
- operators can only be applied to vectors or strings, and imply a run-time
1038
- bounds-check. @xref {Ref.Type.Vec }.
1005
+ In most contexts, the Rust grammar accepts a general @emph {path }, but
1006
+ subsequent passes pay restrict paths occurring in various contexts to refer to
1007
+ slots or items, depending on the semantics of the occurrence. In other words:
1008
+ in some contexts a slot is required (for example, on the left hand side of the
1009
+ copy operator, @pxref {Ref.Expr.Copy }) and in other contexts an item is
1010
+ required (for example, as a type parameter, @pxref {Ref.Item }). In no case is
1011
+ the grammar made ambiguous by accepting a general path and interpreting the
1012
+ reference in later passes. @xref {Ref.Gram }.
1039
1013
1040
- An example of an lval with a dynamic indexing operator :
1014
+ An example of a path with type parameters :
1041
1015
@example
1042
- x.y.(1 + v).z ;
1016
+ m::map[int,str] ;
1043
1017
@end example
1044
1018
1045
1019
@page
@@ -1110,8 +1084,8 @@ all members of the crate have canonical path names. @xref{Ref.Path}. The
1110
1084
the crate: these are either directory modules, corresponding to directories in
1111
1085
the filesystem of the compilation environment, or file modules, corresponding
1112
1086
to Rust source files. The names given to such modules in @code {mod } directives
1113
- become prefixes of the paths of items and slots defined within any included
1114
- Rust source files.
1087
+ become prefixes of the paths of items defined within any included Rust source
1088
+ files.
1115
1089
1116
1090
The @code {use } directives within the crate specify @emph {other crates } to scan
1117
1091
for, locate, import into the crate's module namespace during compilation, and
@@ -1381,7 +1355,7 @@ Some operations implicitly dereference boxes. Examples of such @dfn{implicit
1381
1355
dereference } operations are:
1382
1356
@itemize
1383
1357
@item arithmetic operators (@code {x + y - z })
1384
- @item name-component selection (@code {x.y.z })
1358
+ @item field selection (@code {x.y.z })
1385
1359
@end itemize
1386
1360
1387
1361
An example of an implicit-dereference operation performed on box values:
@@ -1731,9 +1705,9 @@ declarations. @xref{Ref.Comp.Crate}.
1731
1705
1732
1706
An example of an import:
1733
1707
@example
1734
- import std. math. sin;
1708
+ import std:: math:: sin;
1735
1709
fn main() @{
1736
- // Equivalent to 'log std. math. sin(1.0);'
1710
+ // Equivalent to 'log std:: math:: sin(1.0);'
1737
1711
log sin(1.0);
1738
1712
@}
1739
1713
@end example
@@ -1767,8 +1741,8 @@ mod foo @{
1767
1741
@}
1768
1742
1769
1743
fn main() @{
1770
- foo. primary(); // Will compile.
1771
- foo. helper(2,3) // ERROR: will not compile.
1744
+ foo:: primary(); // Will compile.
1745
+ foo:: helper(2,3) // ERROR: will not compile.
1772
1746
@}
1773
1747
@end example
1774
1748
@@ -3268,7 +3242,7 @@ fn read_file_lines(&str path) -> vec[str] @{
3268
3242
vec[str] r;
3269
3243
file f = open_read(path);
3270
3244
for each (str s in lines(f)) @{
3271
- vec. append(r,s);
3245
+ vec:: append(r,s);
3272
3246
@}
3273
3247
ret r;
3274
3248
@}
@@ -3368,7 +3342,7 @@ Example of 4 for loops, all identical:
3368
3342
@example
3369
3343
let v: vec[foo] = [a, b, c];
3370
3344
3371
- for (foo e in v.(0, _vec. len(v))) @{
3345
+ for (foo e in v.(0, vec:: len(v))) @{
3372
3346
bar(e);
3373
3347
@}
3374
3348
@@ -3400,8 +3374,8 @@ Example of a foreach loop:
3400
3374
@example
3401
3375
let txt: str;
3402
3376
let lines: vec[str];
3403
- for each (str s in _str. split(txt, "\n")) @{
3404
- vec. push(lines, s);
3377
+ for each (str s in str:: split(txt, "\n")) @{
3378
+ vec:: push(lines, s);
3405
3379
@}
3406
3380
@end example
3407
3381
@@ -3477,7 +3451,7 @@ let strs: vec[str];
3477
3451
3478
3452
alt @{
3479
3453
case (str s <- p) @{
3480
- vec. append(strs, s);
3454
+ vec:: append(strs, s);
3481
3455
@}
3482
3456
case (c <| x) @{
3483
3457
x++;
@@ -3762,16 +3736,16 @@ expressions can be enabled or disabled via a two-dimensional filtering process:
3762
3736
By Item
3763
3737
3764
3738
Each @emph {item } (module, function, iterator, object, type) in Rust has a
3765
- static name- path within its crate module, and can have logging enabled or
3766
- disabled on a name- path-prefix basis.
3739
+ static path within its crate module, and can have logging enabled or
3740
+ disabled on a path-prefix basis.
3767
3741
3768
3742
@sp 1
3769
3743
@item
3770
3744
By Task
3771
3745
3772
- Each @emph {task } in a running Rust program has a unique ownership-path through
3773
- the task ownership tree, and can have logging enabled or disabled on an
3774
- ownership-path-prefix basis.
3746
+ Each @emph {task } in a running Rust program has a unique ownership relation
3747
+ through the task ownership tree, and can have logging enabled or disabled on
3748
+ an ownership-ancestry basis.
3775
3749
@end itemize
3776
3750
3777
3751
Logging is integrated into the language for efficiency reasons, as well as the
0 commit comments