mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
27d6b3c9b7
Stabilize `core::hint::cold_path` `cold_path` has been around unstably for a while and is a rather useful tool to have. It does what it is supposed to and there are no known remaining issues, so stabilize it here (including const). Newly stable API: ```rust // in core::hint pub const fn cold_path(); ``` I have opted to exclude `likely` and `unlikely` for now since they have had some concerns about ease of use that `cold_path` doesn't suffer from. `cold_path` is also significantly more flexible; in addition to working with boolean `if` conditions, it can be used in `match` arms, `if let`, closures, and other control flow blocks. `likely` and `unlikely` are also possible to implement in user code via `cold_path`, if desired. Closes: https://github.com/rust-lang/rust/issues/136873 (tracking issue) --- There has been some design and implementation work for making `#[cold]` function in more places, such as `if` arms, `match` arms, and closure bodies. Considering a stable `cold_path` will cover all of these usecases, it does not seem worth pursuing a more powerful `#[cold]` as an alternative way to do the same thing. If the lang team agrees, then: Closes: https://github.com/rust-lang/rust/issues/26179 Closes: https://github.com/rust-lang/rust/pull/120193