Skip to content

Commit 994bfa5

Browse files
authored
Document rvalue promotion to 'static.
1 parent 2c29398 commit 994bfa5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/expressions.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ The following expressions can create mutable lvalues:
8484
### Temporary lifetimes
8585

8686
When using an rvalue in most lvalue contexts, a temporary unnamed lvalue is
87-
created and used instead. The lifetime of temporary values is typically the
88-
innermost enclosing statement; the tail expression of a block is considered
89-
part of the statement that encloses the block.
87+
created and used instead, if not promoted to `'static`. Promotion of an
88+
rvalue expression to a `'static` slot occurs when the expression could be
89+
written in a constant, borrowed, and dereferencing that borrow where the
90+
expression was the originally written, without changing the runtime behavior.
91+
That is, the promoted expression can be evaluated at compile-time and the
92+
resulting value does not contain interior mutability or destructors.
93+
Otherwise, lifetime of temporary values is typically the innermost enclosing
94+
statement; the tail expression of a block is considered part of the statement
95+
that encloses the block
9096

9197
When a temporary rvalue is being created that is assigned into a `let`
9298
declaration, however, the temporary is created with the lifetime of the

0 commit comments

Comments
 (0)