惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Cloudbric
Cloudbric
I
InfoQ
V
V2EX
博客园_首页
The Register - Security
The Register - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Vercel News
Vercel News
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
D
DataBreaches.Net
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
B
Blog RSS Feed
A
About on SuperTechFans
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
Spread Privacy
Spread Privacy
F
Full Disclosure
Recorded Future
Recorded Future
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
The Cloudflare Blog
T
Threatpost
T
Tor Project blog
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
A
Arctic Wolf
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Security Latest
Security Latest
The Last Watchdog
The Last Watchdog

Rust Blog

Security Advisory for Cargo (CVE-2026-5223) | Rust Blog Security Advisory for Cargo (CVE-2026-5222) | Rust Blog Project goals update — April 2026 (end of 2025H2) | Rust Blog Rust is participating in Outreachy | Rust Blog Raising the baseline for the `nvptx64-nvidia-cuda` target | Rust Blog Announcing Google Summer of Code 2026 selected projects | Rust Blog Announcing Rust 1.95.0 | Rust Blog docs.rs: building fewer targets by default | Rust Blog Changes to WebAssembly targets and handling undefined symbols | Rust Blog Announcing Rust 1.94.1 | Rust Blog Security advisory for Cargo | Rust Blog What we heard about Rust's challenges | Rust Blog Call for Testing: Build Dir Layout v2 | Rust Blog Announcing rustup 1.29.0 | Rust Blog Announcing Rust 1.94.0 | Rust Blog 2025 State of Rust Survey Results | Rust Blog Rust debugging survey 2026 | Rust Blog Update on the October 15, 2018 incident on crates.io Announcing Rust 1.29.2 Announcing Rust 1.29 Announcing Rust 1.28 What is Rust 2018? Announcing Rust 1.27.2 Announcing Rust 1.27.1 Security Advisory for rustdoc Announcing Rust 1.27 Announcing Rust 1.26.2 Announcing Rust 1.26.1 Rust turns three Announcing Rust 1.26 The Rust Team All Hands in Berlin: a Recap Increasing Rust’s Reach 2018 Announcing Rust 1.25 Rust's 2018 roadmap Announcing Rust 1.24.1 Announcing Rust 1.24 The 2018 Rust Event Lineup Announcing Rust 1.23 New Year's Rust: A Call for Community Blogposts Rust in 2017: what we achieved Announcing Rust 1.22 (and 1.22.1) Fearless Concurrency in Firefox Quantum Announcing Rust 1.21 impl Future for Rust Rust 2017 Survey Results Announcing Rust 1.20 Announcing Rust 1.19 The 2017 Rust Conference Lineup Rust's 2017 roadmap, six months in Increasing Rust’s Reach Announcing Rust 1.18 Two years of Rust The Rust Libz Blitz Launching the 2017 State of Rust Survey Announcing Rust 1.17 Announcing Rust 1.16 Rust's language ergonomics initiative Announcing Rust 1.15.1 Rust's 2017 roadmap Announcing Rust 1.15 Announcing Rust 1.14 Announcing the First Underhanded Rust Contest Announcing Rust 1.13 Announcing Rust 1.12.1 Announcing Rust 1.12 Incremental Compilation Announcing Rust 1.11 Shape of errors to come The 2016 Rust Conference Lineup Announcing Rust 1.10 State of Rust Survey 2016 Announcing Rust 1.9 One year of Rust Taking Rust everywhere with rustup Launching the 2016 State of Rust Survey Cargo: predictable dependency management Introducing MIR Announcing Rust 1.8 Announcing Rust 1.7 Announcing Rust 1.6 Announcing Rust 1.5 Announcing Rust 1.4 Announcing Rust 1.3 Rust in 2016 Announcing Rust 1.2 Rust 1.1 stable, the Community Subteam, and RustCamp Announcing Rust 1.0 Abstraction without overhead: traits in Rust Rust Once, Run Everywhere Mixing matching, mutation, and moves in Rust Fearless Concurrency with Rust Announcing Rust 1.0 Beta Announcing Rust 1.0.0.alpha.2 Rust 1.0: status report and final timeline Announcing Rust 1.0 Alpha Rust 1.0: Scheduling the trains Yehuda Katz and Steve Klabnik are joining the Rust Core Team Cargo: Rust's community crate host Stability as a Deliverable Road to Rust 1.0
`if` and `match` in constants on nightly rust | Inside Rust Blog
Dylan MacKenzie on behalf of WG const-eval · 2019-11-25 · via Rust Blog

TLDR; if and match are now usable in constants on the latest nightly.

As a result, you can now write code like the following and have it execute at compile-time:

static PLATFORM: &str = if cfg!(unix) {
    "unix"
} else if cfg!(windows) {
    "windows"
} else {
    "other"
};

const _: () = assert!(std::mem::size_of::<usize>() == 8, "Only 64-bit platforms are supported");

if and match can also be used in the body of a const fn:

const fn gcd(a: u32, b: u32) -> u32 {
    match (a, b) {
        (x, 0) | (0, x) => x,

        (x, y) if x % 2 == 0 && y % 2 == 0 => 2*gcd(x/2, y/2),
        (x, y) | (y, x) if x % 2 == 0 => gcd(x/2, y),

        (x, y) if x < y => gcd((y-x)/2, x),
        (x, y) => gcd((x-y)/2, y),
    }
}

What exactly is going on here?

The following expressions,

  • match
  • if and if let
  • && and ||

can now appear in any of the following contexts,

  • const fn bodies
  • const and associated const initializers
  • static and static mut initializers
  • array initializers
  • const generics (EXPERIMENTAL)

if #![feature(const_if_match)] is enabled for your crate.

You may have noticed that the short-circuiting logic operators, && and ||, were already legal in a const or static. This was accomplished by translating them to their non-short-circuiting equivalents, & and | respectively. Enabling the feature gate will turn off this hack and make && and || behave as you would expect.

As a side-effect of these changes, the assert and debug_assert macros become usable in a const context if #![feature(const_panic)] is also enabled. However, the other assert macros (e.g., assert_eq, debug_assert_ne) remain forbidden, since they need to call Debug::fmt on their arguments.

The looping constructs, while, for, and loop are also forbidden and will be feature-gated separately. As you have seen above, loops can be emulated with recursion as a temporary measure. However, the non-recursive version will usually be more efficient since rust does not (to my knowledge) do tail call optimization.

Finally, the ? operator remains forbidden in a const context, since its desugaring contains a call to From::from. The design for const trait methods is still being discussed, and both ? and for, which desugars to a call to IntoIterator::into_iter, will not be usable until a final decision is reached.

What's next?

This change will allow a great number of standard library functions to be made const. You can help with this process! To get started, here's a list of numeric functions that can be constified with little effort. Conversion to a const fn requires two steps. First, const is added to a function definition along with a #[rustc_const_unstable] attribute. This allows nightly users to call it in a const context. Then, after a period of experimentation, the attribute is removed and the constness of that function is stabilized. See #61635 for an example of the first step and #64028 for an example of the second.

Personally, I've looked forward to this feature for a long time, and I can't wait to start playing with it. If you feel the same, I would greatly appreciate if you tested the limits of this feature! Try to sneak Cells and types with Drop impls into places they shouldn't be allowed, blow up the stack with poorly implemented recursive functions (see gcd above), and let us know if something goes horribly wrong.

What took you so long?

The Miri engine, which rust uses under the hood for compile-time function evaluation, has been capable of this for a while now. However, rust needs to statically guarantee certain properties about variables in a const, such as whether they allow for interior mutability or whether they have a Drop implementation that needs to be called. For example, we must reject the following code since it would result in a const being mutable at runtime!

const CELL: &std::cell::Cell<i32> = &std::cell::Cell::new(42); // Not allowed...

fn main() {
    CELL.set(0);
    println!("{}", CELL.get()); // otherwise this could print `0`!!!
}

However, it is sometimes okay for a const to contain a reference to a type that may have interior mutability, as long as we can prove that the actual value of that type does not. This is particularly useful for enums with a "unit variant" (e.g., Option::None).

const NO_CELL: Option<&std::cell::Cell<i32>> = None; // OK

A more detailed (but non-normative) treatment of the rules for Drop and for interior mutability in a const context can be found on the const-eval repo.

It is not trivial to guarantee properties about the value of a variable when complex control flow such as loops and conditionals is involved. Implementing this feature required extending the existing dataflow framework in rust so that we could properly track the value of each local across the control-flow graph. At the moment, the analysis is very conservative, especially when values are moved in and out of compound data types. For example, the following will not compile, even when the feature gate is enabled.

const fn imprecise() -> Vec<i32> {
    let tuple: (Vec<i32>,) = (Vec::new(),);
    tuple.0
}

Even though the Vec created by Vec::new will never actually be dropped inside the const fn, we don't detect that all fields of tuple have been moved out of, and thus conservatively assume that the drop impl for tuple will run. While this particular case is trivial, there are other, more complex ones that would require a more comprehensive solution. It is an open question how precise we want to be here, since more precision means longer compile times, even for users that have no need for more expressiveness.