Skip to content

Commit ec5a4b7

Browse files
committed
Document rvalue promotion to 'static.
1 parent a3dcfe5 commit ec5a4b7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/expressions.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +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
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 (these
93+
properties are determined based on the value where possible, e.g. `&None`
94+
always has the type `&'static Option<_>`, as it contains nothing disallowed).
95+
Otherwise, the lifetime of temporary values is typically
8896

8997
- the innermost enclosing statement; the tail expression of a block is
9098
considered part of the statement that encloses the block, or

0 commit comments

Comments
 (0)