TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rust oddness: integer literal references?

4 点作者 melvinroest超过 1 年前

1 comment

steveklabnik超过 1 年前
A more formal description of this behavior: Rust does temporary lifetime extension: <a href="https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;reference&#x2F;destructors.html#temporary-lifetime-extension" rel="nofollow">https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;reference&#x2F;destructors.html#...</a><p><pre><code> let x = &amp;5; &#x2F;&#x2F; 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:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;reference&#x2F;destructors.html?#constant-promotion" rel="nofollow">https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;reference&#x2F;destructors.html?...</a><p><pre><code> let x: &amp;&#x27;static i32 = &amp;5; </code></pre> (this was originally called &quot;rvalue static promotion&quot; but Rust has since moved away from the rvalue&#x2F;lvalue terminology since that time)