From ec5a4b7a413cd09cd0fc7f6a3c9a36512831583b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 13 Aug 2017 11:38:21 +0300 Subject: [PATCH] Document rvalue promotion to 'static. --- src/expressions.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/expressions.md b/src/expressions.md index 1653b816d..0c84fbe94 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -84,7 +84,15 @@ The following expressions can create mutable lvalues: ### Temporary lifetimes When using an rvalue in most lvalue contexts, a temporary unnamed lvalue is -created and used instead. The lifetime of temporary values is typically +created and used instead, if not promoted to `'static`. Promotion of an +rvalue expression to a `'static` slot occurs when the expression could be +written in a constant, borrowed, and dereferencing that borrow where the +expression was the originally written, without changing the runtime behavior. +That is, the promoted expression can be evaluated at compile-time and the +resulting value does not contain interior mutability or destructors (these +properties are determined based on the value where possible, e.g. `&None` +always has the type `&'static Option<_>`, as it contains nothing disallowed). +Otherwise, the lifetime of temporary values is typically - the innermost enclosing statement; the tail expression of a block is considered part of the statement that encloses the block, or