3 ms·
Rust oddness: integer literal references?
- steveklabnik 3y agoA more formal description of this behavior: Rust does temporary lifetime extension: https://doc.rust-lang.org/stable/reference/destructors.html#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?#constant-promotion 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)