about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-25 10:35:24 +0000
committerbors <bors@rust-lang.org>2021-04-25 10:35:24 +0000
commit06f0adb34570ba83fee391abeb0bec0eec28a234 (patch)
treed993b31319e211e49286ddb17f099bae694c5cc4
parent13a2615883aa28433383a723a764ca9acb43fd48 (diff)
parent3d16e156aef937ae797892ef05e08b8159a415c4 (diff)
downloadrust-06f0adb34570ba83fee391abeb0bec0eec28a234.tar.gz
rust-06f0adb34570ba83fee391abeb0bec0eec28a234.zip
Auto merge of #84216 - RalfJung:black-box, r=Mark-Simulacrum
move core::hint::black_box under its own feature gate

The `black_box` function had its own RFC and is tracked separately from the `test` feature at https://github.com/rust-lang/rust/issues/64102. Let's reflect this in the feature gate.

To avoid breaking all the benchmarks, libtest's `test::black_box` is a wrapping definition, not a reexport -- this means it is still under the `test` feature gate.
-rw-r--r--compiler/rustc_index/src/lib.rs1
-rw-r--r--library/core/benches/fmt.rs8
-rw-r--r--library/core/src/hint.rs2
-rw-r--r--library/std/src/lib.rs1
-rw-r--r--library/test/src/bench.rs11
-rw-r--r--library/test/src/lib.rs1
-rw-r--r--src/test/ui/consts/cast-discriminant-zst-enum.rs2
-rw-r--r--src/test/ui/consts/const_discriminant.rs2
-rw-r--r--src/test/ui/sanitize/address.rs2
-rw-r--r--src/test/ui/sanitize/hwaddress.rs2
-rw-r--r--src/test/ui/sanitize/leak.rs2
-rw-r--r--src/test/ui/sanitize/memory.rs2
12 files changed, 23 insertions, 13 deletions
diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs
index 9c306d02512..4c73b7bf612 100644
--- a/compiler/rustc_index/src/lib.rs
+++ b/compiler/rustc_index/src/lib.rs
@@ -1,4 +1,5 @@
 #![feature(allow_internal_unstable)]
+#![feature(bench_black_box)]
 #![feature(const_panic)]
 #![feature(extend_one)]
 #![feature(iter_zip)]
diff --git a/library/core/benches/fmt.rs b/library/core/benches/fmt.rs
index 2792181acc3..9df66263459 100644
--- a/library/core/benches/fmt.rs
+++ b/library/core/benches/fmt.rs
@@ -112,7 +112,7 @@ fn write_str_macro_debug(bh: &mut Bencher) {
 #[bench]
 fn write_u128_max(bh: &mut Bencher) {
     bh.iter(|| {
-        std::hint::black_box(format!("{}", u128::MAX));
+        test::black_box(format!("{}", u128::MAX));
     });
 }
 
@@ -120,20 +120,20 @@ fn write_u128_max(bh: &mut Bencher) {
 fn write_u128_min(bh: &mut Bencher) {
     bh.iter(|| {
         let s = format!("{}", 0u128);
-        std::hint::black_box(s);
+        test::black_box(s);
     });
 }
 
 #[bench]
 fn write_u64_max(bh: &mut Bencher) {
     bh.iter(|| {
-        std::hint::black_box(format!("{}", u64::MAX));
+        test::black_box(format!("{}", u64::MAX));
     });
 }
 
 #[bench]
 fn write_u64_min(bh: &mut Bencher) {
     bh.iter(|| {
-        std::hint::black_box(format!("{}", 0u64));
+        test::black_box(format!("{}", 0u64));
     });
 }
diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs
index 313729581ac..f7aec736449 100644
--- a/library/core/src/hint.rs
+++ b/library/core/src/hint.rs
@@ -154,7 +154,7 @@ pub fn spin_loop() {
 /// [`std::convert::identity`]: crate::convert::identity
 #[cfg_attr(not(miri), inline)]
 #[cfg_attr(miri, inline(never))]
-#[unstable(feature = "test", issue = "50297")]
+#[unstable(feature = "bench_black_box", issue = "64102")]
 #[cfg_attr(miri, allow(unused_mut))]
 pub fn black_box<T>(mut dummy: T) -> T {
     // We need to "use" the argument in some way LLVM can't introspect, and on
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 089d43483fc..0ab9f490fd4 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -233,6 +233,7 @@
 #![feature(assert_matches)]
 #![feature(associated_type_bounds)]
 #![feature(atomic_mut_ptr)]
+#![feature(bench_black_box)]
 #![feature(box_syntax)]
 #![feature(c_variadic)]
 #![feature(cfg_accessible)]
diff --git a/library/test/src/bench.rs b/library/test/src/bench.rs
index 169154187f2..7869ba2c041 100644
--- a/library/test/src/bench.rs
+++ b/library/test/src/bench.rs
@@ -1,6 +1,4 @@
 //! Benchmarking module.
-pub use std::hint::black_box;
-
 use super::{
     event::CompletedTest,
     options::BenchMode,
@@ -16,6 +14,15 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
 use std::sync::{Arc, Mutex};
 use std::time::{Duration, Instant};
 
+/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what
+/// `black_box` could do.
+///
+/// See [`std::hint::black_box`] for details.
+#[inline(always)]
+pub fn black_box<T>(dummy: T) -> T {
+    std::hint::black_box(dummy)
+}
+
 /// Manager of the benchmarking runs.
 ///
 /// This is fed into functions marked with `#[bench]` to allow for
diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs
index 2e0864f303c..9adc099aaa5 100644
--- a/library/test/src/lib.rs
+++ b/library/test/src/lib.rs
@@ -24,6 +24,7 @@
 #![feature(rustc_private)]
 #![feature(nll)]
 #![feature(available_concurrency)]
+#![feature(bench_black_box)]
 #![feature(internal_output_capture)]
 #![feature(panic_unwind)]
 #![feature(staged_api)]
diff --git a/src/test/ui/consts/cast-discriminant-zst-enum.rs b/src/test/ui/consts/cast-discriminant-zst-enum.rs
index 9c02d232e13..66b76627c02 100644
--- a/src/test/ui/consts/cast-discriminant-zst-enum.rs
+++ b/src/test/ui/consts/cast-discriminant-zst-enum.rs
@@ -1,6 +1,6 @@
 // run-pass
 // Test a ZST enum whose dicriminant is ~0i128. This caused an ICE when casting to a i32.
-#![feature(test)]
+#![feature(bench_black_box)]
 use std::hint::black_box;
 
 #[derive(Copy, Clone)]
diff --git a/src/test/ui/consts/const_discriminant.rs b/src/test/ui/consts/const_discriminant.rs
index d016d236dbf..a47f6af0296 100644
--- a/src/test/ui/consts/const_discriminant.rs
+++ b/src/test/ui/consts/const_discriminant.rs
@@ -1,6 +1,6 @@
 // run-pass
 #![feature(const_discriminant)]
-#![feature(test)]
+#![feature(bench_black_box)]
 #![allow(dead_code)]
 
 use std::mem::{discriminant, Discriminant};
diff --git a/src/test/ui/sanitize/address.rs b/src/test/ui/sanitize/address.rs
index cee73b0425a..9a26a351d99 100644
--- a/src/test/ui/sanitize/address.rs
+++ b/src/test/ui/sanitize/address.rs
@@ -7,7 +7,7 @@
 // error-pattern: AddressSanitizer: stack-buffer-overflow
 // error-pattern: 'xs' (line 15) <== Memory access at offset
 
-#![feature(test)]
+#![feature(bench_black_box)]
 
 use std::hint::black_box;
 
diff --git a/src/test/ui/sanitize/hwaddress.rs b/src/test/ui/sanitize/hwaddress.rs
index 88769b7cb45..bb6986740d9 100644
--- a/src/test/ui/sanitize/hwaddress.rs
+++ b/src/test/ui/sanitize/hwaddress.rs
@@ -7,7 +7,7 @@
 // run-fail
 // error-pattern: HWAddressSanitizer: tag-mismatch
 
-#![feature(test)]
+#![feature(bench_black_box)]
 
 use std::hint::black_box;
 
diff --git a/src/test/ui/sanitize/leak.rs b/src/test/ui/sanitize/leak.rs
index c9f10fe4f46..f63f81352da 100644
--- a/src/test/ui/sanitize/leak.rs
+++ b/src/test/ui/sanitize/leak.rs
@@ -6,7 +6,7 @@
 // run-fail
 // error-pattern: LeakSanitizer: detected memory leaks
 
-#![feature(test)]
+#![feature(bench_black_box)]
 
 use std::hint::black_box;
 use std::mem;
diff --git a/src/test/ui/sanitize/memory.rs b/src/test/ui/sanitize/memory.rs
index a26649a5800..48a482a13aa 100644
--- a/src/test/ui/sanitize/memory.rs
+++ b/src/test/ui/sanitize/memory.rs
@@ -13,7 +13,7 @@
 
 #![feature(core_intrinsics)]
 #![feature(start)]
-#![feature(test)]
+#![feature(bench_black_box)]
 
 use std::hint::black_box;
 use std::mem::MaybeUninit;