A more formal description of this behavior: Rust does temporary lifetime extension: <a href="https://doc.rust-lang.org/stable/reference/destructors.html#temporary-lifetime-extension" rel="nofollow">https://doc.rust-lang.org/stable/reference/destructors.html#...</a><p><pre><code> let x = &5;
// x is still valid here because the 5 is no longer a temporary but lives for the rest of the block
</code></pre>
As well as constant promotion, not discussed in the post but similar! <a href="https://doc.rust-lang.org/stable/reference/destructors.html?#constant-promotion" rel="nofollow">https://doc.rust-lang.org/stable/reference/destructors.html?...</a><p><pre><code> let x: &'static i32 = &5;
</code></pre>
(this was originally called "rvalue static promotion" but Rust has since moved away from the rvalue/lvalue terminology since that time)