Skip to content

Commit fe1165f

Browse files
committed
Tighten up language surrounding declarations, assignments, inits, lvals.
1 parent e325d02 commit fe1165f

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

doc/rust.md

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,27 +1435,11 @@ let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
14351435
init : [ '=' | '<-' ] expr ;
14361436
~~~~~~~~
14371437

1438-
1439-
A _slot declaration_ has one of two forms:
1440-
1441-
* `let` `pattern` `optional-init`;
1442-
* `let` `pattern` : `type` `optional-init`;
1443-
1444-
Where `type` is a type expression, `pattern` is an irrefutable pattern (often
1445-
just the name of a single slot), and `optional-init` is an optional
1446-
initializer. If present, the initializer consists of either an assignment
1447-
operator (`=`) or move operator (`<-`), followed by an expression.
1448-
1449-
Both forms introduce a new slot into the enclosing block scope. The new slot
1450-
is visible from the point of declaration until the end of the enclosing block
1451-
scope.
1452-
1453-
The former form, with no type annotation, causes the compiler to infer the
1454-
static type of the slot through unification with the types of values assigned
1455-
to the slot in the remaining code in the block scope. Inference only occurs on
1456-
frame-local variable, not argument slots. Function signatures must
1457-
always declare types for all argument slots.
1458-
1438+
A _slot declaration_ introduces a new set of slots, given by a pattern.
1439+
The pattern may be followed by a type annotation, and/or an initializer expression.
1440+
When no type annotation is given, the compiler will infer the type,
1441+
or signal an error if insufficient type information is available for definite inference.
1442+
Any slots introduced by a slot declaration are visible from the point of declaration until the end of the enclosing block scope.
14591443

14601444
### Expression statements
14611445

@@ -1487,7 +1471,8 @@ The evaluation of an expression depends both on its own category and the context
14871471
Path, field and index expressions are lvalues.
14881472
All other expressions are rvalues.
14891473

1490-
The left operand of an assignment expression and the operand of the borrow operator are lvalue contexts.
1474+
The left operand of an assignment, compound-assignment, or binary move expression is an lvalue context,
1475+
as is the single operand of a borrow, unary copy or move expression, and _both_ operands of a swap expression.
14911476
All other expression contexts are rvalue contexts.
14921477

14931478
When an lvalue is evaluated in an _lvalue context_, it denotes a memory location;
@@ -1572,9 +1557,8 @@ myrecord.myfield;
15721557
{a: 10, b: 20}.a;
15731558
~~~~~~~~
15741559

1575-
A field access on a record is an _lval_ referring to the value of that
1576-
field. When the field is mutable, it can be
1577-
[assigned](#assignment-expressions) to.
1560+
A field access on a record is an [lvalue](#lvalues-rvalues-and-temporaries) referring to the value of that field.
1561+
When the field is mutable, it can be [assigned](#assignment-expressions) to.
15781562

15791563
When the type of the expression to the left of the dot is a boxed
15801564
record, it is automatically derferenced to make the field access
@@ -1615,7 +1599,7 @@ idx_expr : expr '[' expr ']'
16151599

16161600
[Vector](#vector-types)-typed expressions can be indexed by writing a
16171601
square-bracket-enclosed expression (the index) after them. When the
1618-
vector is mutable, the resulting _lval_ can be assigned to.
1602+
vector is mutable, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be assigned to.
16191603

16201604
Indices are zero-based, and may be of any integral type. Vector access
16211605
is bounds-checked at run-time. When the check fails, it will put the
@@ -1641,7 +1625,7 @@ operators, before the expression they apply to.
16411625
`*`
16421626
: Dereference. When applied to a [box](#box-types) or
16431627
[resource](#resources) type, it accesses the inner value. For
1644-
mutable boxes, the resulting _lval_ can be assigned to. For
1628+
mutable boxes, the resulting [lvalue](#lvalues-rvalues-and-temporaries) can be assigned to. For
16451629
[enums](#enumerated-types) that have only a single variant,
16461630
containing a single parameter, the dereference operator accesses
16471631
this parameter.
@@ -1762,11 +1746,11 @@ types.
17621746

17631747
#### Binary move expressions
17641748

1765-
A _binary move expression_ consists of an *lval* followed by a left-pointing
1766-
arrow (`<-`) and an *rval* expression.
1749+
A _binary move expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) followed by a left-pointing
1750+
arrow (`<-`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
17671751

1768-
Evaluating a move expression causes, as a side effect, the *rval* to be
1769-
*moved* into the *lval*. If the *rval* was itself an *lval*, it must be a
1752+
Evaluating a move expression causes, as a side effect, the rvalue to be
1753+
*moved* into the lvalue. If the rvalue was itself an lvalue, it must be a
17701754
local variable, as it will be de-initialized in the process.
17711755

17721756
Evaluating a move expression does not change reference counts, nor does it
@@ -1792,17 +1776,13 @@ y.z <- c;
17921776

17931777
#### Swap expressions
17941778

1795-
A _swap expression_ consists of an *lval* followed by a bi-directional arrow
1796-
(`<->`) and another *lval* expression.
1779+
A _swap expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) followed by a bi-directional arrow (`<->`) and another [lvalue](#lvalues-rvalues-and-temporaries).
17971780

1798-
Evaluating a swap expression causes, as a side effect, the values held in the
1799-
left-hand-side and right-hand-side *lvals* to be exchanged indivisibly.
1781+
Evaluating a swap expression causes, as a side effect, the values held in the left-hand-side and right-hand-side [lvalues](#lvalues-rvalues-and-temporaries) to be exchanged indivisibly.
18001782

1801-
Evaluating a swap expression neither changes reference counts nor deeply
1802-
copies any unique structure pointed to by the moved
1803-
*rval*. Instead, the swap expression represents an indivisible *exchange of
1804-
ownership* between the right-hand-side and the left-hand-side of the
1805-
expression. No allocation or destruction is entailed.
1783+
Evaluating a swap expression neither changes reference counts nor deeply copies any unique structure pointed to by the moved [rvalue](#lvalues-rvalues-and-temporaries).
1784+
Instead, the swap expression represents an indivisible *exchange of ownership* between the right-hand-side and the left-hand-side of the expression.
1785+
No allocation or destruction is entailed.
18061786

18071787
An example of three different swap expressions:
18081788

@@ -1821,8 +1801,8 @@ y.z <-> b.c;
18211801

18221802
#### Assignment expressions
18231803

1824-
An _assignment expression_ consists of an *lval* expression followed by an
1825-
equals sign (`=`) and an *rval* expression.
1804+
An _assignment expression_ consists of an [lvalue](#lvalues-rvalues-and-temporaries) expression followed by an
1805+
equals sign (`=`) and an [rvalue](#lvalues-rvalues-and-temporaries) expression.
18261806

18271807
Evaluating an assignment expression is equivalent to evaluating a [binary move
18281808
expression](#binary-move-expressions) applied to a [unary copy

0 commit comments

Comments
 (0)