Skip to content

Commit ce31fd9

Browse files
tgross35gitbot
authored and
gitbot
committed
Stabilize const_black_box
This has been unstably const since [1], but a tracking issue was never created. Per discussion on Zulip [2], there should not be any blockers to making this const-stable. The function does not provide any functionality at compile time but does allow code reuse between const- and non-const functions, so stabilize it here. [1]: rust-lang#92226 [2]: https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const_black_box
1 parent 7fbae89 commit ce31fd9

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

core/src/hint.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,11 @@ pub fn spin_loop() {
468468
/// // No assumptions can be made about either operand, so the multiplication is not optimized out.
469469
/// let y = black_box(5) * black_box(10);
470470
/// ```
471+
///
472+
/// During constant evaluation, `black_box` is treated as a no-op.
471473
#[inline]
472474
#[stable(feature = "bench_black_box", since = "1.66.0")]
473-
#[rustc_const_unstable(feature = "const_black_box", issue = "none")]
475+
#[rustc_const_stable(feature = "const_black_box", since = "CURRENT_RUSTC_VERSION")]
474476
pub const fn black_box<T>(dummy: T) -> T {
475477
crate::intrinsics::black_box(dummy)
476478
}

core/src/intrinsics/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3725,6 +3725,7 @@ pub const unsafe fn compare_bytes(_left: *const u8, _right: *const u8, _bytes: u
37253725
#[rustc_nounwind]
37263726
#[rustc_intrinsic]
37273727
#[rustc_intrinsic_must_be_overridden]
3728+
#[rustc_intrinsic_const_stable_indirect]
37283729
pub const fn black_box<T>(_dummy: T) -> T {
37293730
unimplemented!()
37303731
}

coretests/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(bstr)]
1515
#![feature(cell_update)]
1616
#![feature(clone_to_uninit)]
17-
#![feature(const_black_box)]
1817
#![feature(const_eval_select)]
1918
#![feature(const_swap_nonoverlapping)]
2019
#![feature(const_trait_impl)]

0 commit comments

Comments
 (0)