From cb4c747e9f6b51f8e44caab27ca376b59df3a56d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 5 Oct 2012 14:19:50 -0700 Subject: [PATCH] Add section on lvals, rvals and temps. --- doc/rust.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/rust.md b/doc/rust.md index 8e0a03865533..e514990ab8ec 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1468,6 +1468,25 @@ structure of expressions. Blocks themselves are expressions, so the nesting sequence of block, statement, expression, and block can repeatedly nest to an arbitrary depth. +#### Lvalues, rvalues and temporaries + +Expressions are divided into two main categories: _lvalues_ and _rvalues_. +Likewise within each expression, sub-expressions may occur in _lvalue context_ or _rvalue context_. +The evaluation of an expression depends both on its own category and the context it occurs within. + +Path, field and index expressions are lvalues. +All other expressions are rvalues. + +The left operand of an assignment expression and the operand of the borrow operator are lvalue contexts. +All other expression contexts are rvalue contexts. + +When an lvalue is evaluated in an _lvalue context_, it denotes a memory location; +when evaluated in an _rvalue context_, it denotes the value held _in_ that memory location. + +When an rvalue is used in lvalue context, a temporary un-named lvalue is created and used instead. +A temporary's lifetime equals the largest lifetime of any borrowed pointer that points to it. + + ### Literal expressions A _literal expression_ consists of one of the [literal](#literals)