[–] steveklabnik 2y ago ↗ A more formal description of this behavior: Rust does temporary lifetime extension: https://doc.rust-lang.org/stable/reference/destructors.html#... let x = &5; // x is still valid here because the 5 is no longer a temporary but lives for the rest of the block As well as constant promotion, not discussed in the post but similar! https://doc.rust-lang.org/stable/reference/destructors.html?... let x: &'static i32 = &5; (this was originally called "rvalue static promotion" but Rust has since moved away from the rvalue/lvalue terminology since that time)
1 comment
[ 2.9 ms ] story [ 11.2 ms ] thread