Skip to content

Commit cb4c747

Browse files
committed
Add section on lvals, rvals and temps.
1 parent 6c2c694 commit cb4c747

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/rust.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,25 @@ structure of expressions. Blocks themselves are expressions, so the nesting
14681468
sequence of block, statement, expression, and block can repeatedly nest to an
14691469
arbitrary depth.
14701470

1471+
#### Lvalues, rvalues and temporaries
1472+
1473+
Expressions are divided into two main categories: _lvalues_ and _rvalues_.
1474+
Likewise within each expression, sub-expressions may occur in _lvalue context_ or _rvalue context_.
1475+
The evaluation of an expression depends both on its own category and the context it occurs within.
1476+
1477+
Path, field and index expressions are lvalues.
1478+
All other expressions are rvalues.
1479+
1480+
The left operand of an assignment expression and the operand of the borrow operator are lvalue contexts.
1481+
All other expression contexts are rvalue contexts.
1482+
1483+
When an lvalue is evaluated in an _lvalue context_, it denotes a memory location;
1484+
when evaluated in an _rvalue context_, it denotes the value held _in_ that memory location.
1485+
1486+
When an rvalue is used in lvalue context, a temporary un-named lvalue is created and used instead.
1487+
A temporary's lifetime equals the largest lifetime of any borrowed pointer that points to it.
1488+
1489+
14711490
### Literal expressions
14721491

14731492
A _literal expression_ consists of one of the [literal](#literals)

0 commit comments

Comments
 (0)