@@ -132,7 +132,7 @@ The following productions in the Rust grammar are defined in terms of
132
132
Unicode properties: ` ident ` , ` non_null ` , ` non_star ` , ` non_eol ` , ` non_slash ` ,
133
133
` non_single_quote ` and ` non_double_quote ` .
134
134
135
- ### Identifier
135
+ ### Identifiers
136
136
137
137
The ` ident ` production is any nonempty Unicode string of the following form:
138
138
@@ -254,8 +254,8 @@ are excluded from the `ident` rule.
254
254
A literal is an expression consisting of a single token, rather than a
255
255
sequence of tokens, that immediately and directly denotes the value it
256
256
evaluates to, rather than referring to it by name or some other evaluation
257
- rule. A literal is a form of [ constant expression] ( #constant-expression ) , so
258
- is evaluated (primarily) at compile time.
257
+ rule. A literal is a form of constant expression, so is evaluated (primarily)
258
+ at compile time.
259
259
260
260
~~~~~~~~ {.ebnf .gram}
261
261
literal : string_lit | char_lit | num_lit ;
@@ -439,14 +439,13 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>'
439
439
~~~~~~~~
440
440
441
441
A _ path_ is a sequence of one or more path components _ logically_ separated by
442
- a namespace qualifier (` :: ` ). If a path consists of only one component, it
443
- may refer to either an [ item] ( #items ) or a [ variable ] ( #variables ) in a local
442
+ a namespace qualifier (` :: ` ). If a path consists of only one component, it may
443
+ refer to either an [ item] ( #items ) or a [ slot ] ( #slot-declarations ) in a local
444
444
control scope. If a path has multiple components, it refers to an item.
445
445
446
- Every item has a _ canonical path_ within its [ crate] ( #crates ) , but the path
447
- naming an item is only meaningful within a given crate. There is no global
448
- namespace across crates; an item's canonical path merely identifies it within
449
- the crate.
446
+ Every item has a _ canonical path_ within its crate, but the path naming an
447
+ item is only meaningful within a given crate. There is no global namespace
448
+ across crates; an item's canonical path merely identifies it within the crate.
450
449
451
450
Two examples of simple paths consisting of only identifier components:
452
451
@@ -457,11 +456,10 @@ x::y::z;
457
456
458
457
Path components are usually [ identifiers] ( #identifiers ) , but the trailing
459
458
component of a path may be an angle-bracket-enclosed list of type
460
- arguments. In [ expression] ( #expressions ) context, the type
461
- argument list is given after a final (` :: ` ) namespace qualifier in order to
462
- disambiguate it from a relational expression involving the less-than symbol
463
- (` < ` ). In [ type expression] ( #type-expressions ) context, the final namespace
464
- qualifier is omitted.
459
+ arguments. In [ expression] ( #expressions ) context, the type argument list is
460
+ given after a final (` :: ` ) namespace qualifier in order to disambiguate it
461
+ from a relational expression involving the less-than symbol (` < ` ). In type
462
+ expression context, the final namespace qualifier is omitted.
465
463
466
464
Two examples of paths with type arguments:
467
465
@@ -569,7 +567,7 @@ implicitly by combining the module name with the file extension `.rs`. The
569
567
module contained in that source file is bound to the module path formed by
570
568
the ` dir_directive ` modules containing the ` source_directive ` .
571
569
572
- ## Source file
570
+ ## Source files
573
571
574
572
A source file contains a ` module ` : that is, a sequence of zero or more
575
573
` item ` definitions. Each source file is an implicit module, the name and
@@ -590,12 +588,11 @@ item : mod_item | fn_item | type_item | enum_item
590
588
| res_item | iface_item | impl_item ;
591
589
~~~~~~~~
592
590
593
- An _ item_ is a component of a crate; some module items can be defined in
594
- [ crate files] ( #crate-files ) , but most are defined in [ source
595
- files] ( #source-files ) . Items are organized within a crate by a nested set of
596
- [ modules] ( #modules ) . Every crate has a single "outermost" anonymous module;
597
- all further items within the crate have [ paths] ( #paths ) within the module tree
598
- of the crate.
591
+ An _ item_ is a component of a crate; some module items can be defined in crate
592
+ files, but most are defined in source files. Items are organized within a
593
+ crate by a nested set of [ modules] ( #modules ) . Every crate has a single
594
+ "outermost" anonymous module; all further items within the crate have
595
+ [ paths] ( #paths ) within the module tree of the crate.
599
596
600
597
Items are entirely determined at compile-time, remain constant during
601
598
execution, and may reside in read-only memory.
@@ -821,9 +818,10 @@ mod foo {
821
818
A _ function item_ defines a sequence of [ statements] ( #statements ) and an
822
819
optional final [ expression] ( #expressions ) associated with a name and a set of
823
820
parameters. Functions are declared with the keyword ` fn ` . Functions declare a
824
- set of * input [ slots] ( #slots ) * as parameters, through which the caller passes
825
- arguments into the function, and an * output [ slot] ( #slots ) * through which the
826
- function passes results back to the caller.
821
+ set of * input [ slots] ( #slot-declarations ) * as parameters, through which the
822
+ caller passes arguments into the function, and an * output
823
+ [ slot] ( #slot-declarations ) * through which the function passes results back to
824
+ the caller.
827
825
828
826
A function may also be copied into a first class * value* , in which case the
829
827
value has the corresponding [ * function type* ] ( #function-types ) , and can be
@@ -1020,9 +1018,10 @@ accessed through the components `x` and `y`, and laid out in memory with the
1020
1018
1021
1019
### Enumerations
1022
1020
1023
- An _ enumeration item_ simultaneously declares a new nominal [ enumerated
1024
- type] ( #enumerated-type ) as well as a set of * constructors* that can be used to
1025
- create or pattern-match values of the corresponding enumerated type.
1021
+ An _ enumeration item_ simultaneously declares a new nominal
1022
+ [ enumerated type] ( #enumerated-types ) as well as a set of * constructors* that
1023
+ can be used to create or pattern-match values of the corresponding enumerated
1024
+ type.
1026
1025
1027
1026
The constructors of an ` enum ` type may be recursive: that is, each constructor
1028
1027
may take an argument that refers, directly or indirectly, to the enumerated
@@ -1282,13 +1281,14 @@ sequence expression evaluation.
1282
1281
## Statements
1283
1282
1284
1283
A _ statement_ is a component of a block, which is in turn a component of an
1285
- outer [ block- expression] ( #block- expressions ) or [ function] ( #functions ) . When a
1286
- function is spawned into a [ task] ( #tasks ) , the task * executes* statements in
1287
- an order determined by the body of the enclosing function. Each statement
1288
- causes the task to perform certain actions.
1284
+ outer [ expression] ( #expressions ) or [ function] ( #functions ) . When a function is
1285
+ spawned into a [ task] ( #tasks ) , the task * executes* statements in an order
1286
+ determined by the body of the enclosing function. Each statement causes the
1287
+ task to perform certain actions.
1289
1288
1290
- Rust has two kinds of statement: [ declarations] ( #declarations ) and
1291
- [ expressions] ( #expressions ) .
1289
+ Rust has two kinds of statement:
1290
+ [ declaration statements] ( #declaration-statements ) and
1291
+ [ expression statements] ( #expression-statements ) .
1292
1292
1293
1293
A declaration serves to introduce a * name* that can be used in the block
1294
1294
* scope* enclosing the statement: all statements before and after the
@@ -1310,9 +1310,8 @@ arbitrary depth.
1310
1310
1311
1311
### Declaration statements
1312
1312
1313
- A _ declaration statement_ is one that introduces a * name* into the
1314
- enclosing statement block. The declared name may denote a new slot or a new
1315
- item.
1313
+ A _ declaration statement_ is one that introduces a * name* into the enclosing
1314
+ statement block. The declared name may denote a new slot or a new item.
1316
1315
1317
1316
#### Item declarations
1318
1317
@@ -1352,7 +1351,7 @@ scope.
1352
1351
The former form, with no type annotation, causes the compiler to infer the
1353
1352
static type of the slot through unification with the types of values assigned
1354
1353
to the slot in the remaining code in the block scope. Inference only occurs on
1355
- frame-local slots , not argument slots. Function signatures must
1354
+ frame-local variable , not argument slots. Function signatures must
1356
1355
always declare types for all argument slots.
1357
1356
1358
1357
@@ -1722,11 +1721,11 @@ Evaluating a copy expression first evaluates the argument expression, then
1722
1721
copies the resulting value, allocating any memory necessary to hold the new
1723
1722
copy.
1724
1723
1725
- [ Shared boxes] ( #shared- box-types ) (type ` @ ` ) are, as usual, shallow-copied, as
1726
- they may be cyclic. [ Unique boxes] ( #unique- box-types ) ,
1727
- [ vectors ] ( #vector-types ) and similar unique types are deep-copied.
1724
+ [ Shared boxes] ( #box-types ) (type ` @ ` ) are, as usual, shallow-copied, as they
1725
+ may be cyclic. [ Unique boxes] ( #box-types ) , [ vectors ] ( #vector-types ) and
1726
+ similar unique types are deep-copied.
1728
1727
1729
- Since the binary [ assignment operator] ( #assignment-operator ) ` = ` performs a
1728
+ Since the binary [ assignment operator] ( #assignment-expressions ) ` = ` performs a
1730
1729
copy implicitly, the unary copy operator is typically only used to cause an
1731
1730
argument to a function to be copied and passed by value.
1732
1731
@@ -1826,7 +1825,7 @@ bound slot in the bound function's signature, space is allocated in the hidden
1826
1825
tuple and populated with a copy of the bound value.
1827
1826
1828
1827
A ` bind ` expression is an alternative way of constructing a shared function
1829
- closure; the [ ` fn@ ` expression] ( #shared-function-expression ) form is another
1828
+ closure; the [ ` fn@ ` expression] ( #shared-function-expressions ) form is another
1830
1829
way.
1831
1830
1832
1831
### Shared function expressions
@@ -1966,8 +1965,8 @@ patterns must equal the type of the head expression.
1966
1965
To execute an ` alt ` expression, first the head expression is evaluated, then
1967
1966
its value is sequentially compared to the patterns in the arms until a match
1968
1967
is found. The first arm with a matching pattern is chosen as the branch target
1969
- of the ` alt ` , any variables bound by the pattern are assigned to local slots
1970
- in the arm's block, and control enters the block.
1968
+ of the ` alt ` , any variables bound by the pattern are assigned to local
1969
+ variables in the arm's block, and control enters the block.
1971
1970
1972
1971
An example of an ` alt ` expression:
1973
1972
@@ -2378,11 +2377,11 @@ Future versions of Rust will address these issues.
2378
2377
2379
2378
# Types and typestates
2380
2379
2381
- ## Type system
2380
+ ## Types
2382
2381
2383
2382
Every slot and value in a Rust program has a type. The _ type_ of a * value*
2384
2383
defines the interpretation of the memory holding it. The type of a * slot* may
2385
- also include [ constraints] ( #constrained-types ) .
2384
+ also include [ constraints] ( #constraints ) .
2386
2385
2387
2386
Built-in types and type-constructors are tightly integrated into the language,
2388
2387
in nontrivial ways that are not possible to emulate in user-defined
@@ -2457,7 +2456,6 @@ A value of type `str` is a Unicode string, represented as a vector of 8-bit
2457
2456
unsigned bytes holding a sequence of UTF-8 codepoints.
2458
2457
2459
2458
2460
-
2461
2459
### Record types
2462
2460
2463
2461
The record type-constructor forms a new heterogeneous product of values.^[ The
@@ -2568,8 +2566,8 @@ Unsafe pointers (`*`)
2568
2566
### Function types
2569
2567
2570
2568
The function type-constructor ` fn ` forms new function types. A function type
2571
- consists of a sequence of input slots, an optional set of [ input
2572
- constraints] ( #input- constraints ) and an output slot.
2569
+ consists of a sequence of input slots, an optional set of
2570
+ [ input constraints] ( #constraints ) and an output slot.
2573
2571
2574
2572
An example of a ` fn ` type:
2575
2573
@@ -2916,23 +2914,23 @@ references to any boxes; the remainder of its heap is immediately freed.
2916
2914
2917
2915
A task's stack contains slots.
2918
2916
2919
- A _ slot_ is a component of a stack frame. A slot is either * local* or
2920
- a * reference* .
2917
+ A _ slot_ is a component of a stack frame. A slot is either a * local variable *
2918
+ or a * reference* .
2921
2919
2922
- A _ local _ slot (or * stack-local* allocation) holds a value directly,
2920
+ A _ local variable _ (or * stack-local* allocation) holds a value directly,
2923
2921
allocated within the stack's memory. The value is a part of the stack frame.
2924
2922
2925
2923
A _ reference_ references a value outside the frame. It may refer to a
2926
2924
value allocated in another frame * or* a boxed value in the heap. The
2927
2925
reference-formation rules ensure that the referent will outlive the reference.
2928
2926
2929
- Local slots are always implicitly mutable.
2927
+ Local variables are always implicitly mutable.
2930
2928
2931
- Local slots are not initialized when allocated; the entire frame worth of
2932
- local slots are allocated at once, on frame-entry, in an uninitialized
2929
+ Local variables are not initialized when allocated; the entire frame worth of
2930
+ local variables are allocated at once, on frame-entry, in an uninitialized
2933
2931
state. Subsequent statements within a function may or may not initialize the
2934
- local slots . Local slots can be used only after they have been initialized;
2935
- this condition is guaranteed by the typestate system.
2932
+ local variables . Local variables can be used only after they have been
2933
+ initialized; this condition is guaranteed by the typestate system.
2936
2934
2937
2935
References are created for function arguments. If the compiler can not prove
2938
2936
that the referred-to value will outlive the reference, it will try to set
@@ -3198,7 +3196,6 @@ Receiving a value is done by a call to the `recv` method on a value of type
3198
3196
` core::comm::port ` . This call causes the receiving task to enter the * blocked
3199
3197
reading* state until a value arrives in the port's receive queue, at which
3200
3198
time the port deques a value to return, and un-blocks the receiving task.
3201
- See [ communication system] ( #communication-system ) .
3202
3199
3203
3200
An example of a * receive* :
3204
3201
0 commit comments