Skip to content

Commit 27d6b3c

Browse files
Rollup merge of #151576 - tgross35:stabilize-cold-path, r=jhpratt
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: #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: #26179 Closes: #120193
2 parents 0a5d0e9 + 2e36598 commit 27d6b3c

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

library/core/src/hint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ pub const fn unlikely(b: bool) -> bool {
724724
/// # Examples
725725
///
726726
/// ```
727-
/// #![feature(cold_path)]
728727
/// use core::hint::cold_path;
729728
///
730729
/// fn foo(x: &[i32]) {
@@ -750,7 +749,6 @@ pub const fn unlikely(b: bool) -> bool {
750749
/// than the branch:
751750
///
752751
/// ```
753-
/// #![feature(cold_path)]
754752
/// use core::hint::cold_path;
755753
///
756754
/// #[inline(always)]
@@ -777,7 +775,8 @@ pub const fn unlikely(b: bool) -> bool {
777775
/// }
778776
/// }
779777
/// ```
780-
#[unstable(feature = "cold_path", issue = "136873")]
778+
#[stable(feature = "cold_path", since = "CURRENT_RUSTC_VERSION")]
779+
#[rustc_const_stable(feature = "cold_path", since = "CURRENT_RUSTC_VERSION")]
781780
#[inline(always)]
782781
pub const fn cold_path() {
783782
crate::intrinsics::cold_path()

library/core/src/intrinsics/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ pub const unsafe fn assume(b: bool) {
409409
/// Therefore, implementations must not require the user to uphold
410410
/// any safety invariants.
411411
///
412-
/// This intrinsic does not have a stable counterpart.
413-
#[unstable(feature = "core_intrinsics", issue = "none")]
412+
/// The stabilized version of this intrinsic is [`core::hint::cold_path`].
414413
#[rustc_intrinsic]
415414
#[rustc_nounwind]
416415
#[miri::intrinsic_fallback_is_spec]

tests/codegen-llvm/hint/cold_path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ compile-flags: -Copt-level=3
22
#![crate_type = "lib"]
3-
#![feature(cold_path)]
43

54
use std::hint::cold_path;
65

0 commit comments

Comments
 (0)