]> git.lizzy.rs Git - rust.git/commitdiff
use standard black_box function
authorRalf Jung <post@ralfj.de>
Mon, 7 Sep 2020 09:26:24 +0000 (11:26 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 7 Sep 2020 09:29:47 +0000 (11:29 +0200)
tests/compile-fail/invalid_bool.rs
tests/run-pass/float.rs
tests/run-pass/u128.rs

index 8d8cce1c7e50e045c6801141cbb87f015ab7987c..796d8220dc19647027faf10df85fab292ce40e92 100644 (file)
@@ -1,11 +1,9 @@
 // Validation makes this fail in the wrong place
 // Make sure we find these even with many checks disabled.
 // compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
-
-#[inline(never)]
-fn dont_optimize<T>(x: T) -> T { x }
+#![feature(test)]
 
 fn main() {
     let b = unsafe { std::mem::transmute::<u8, bool>(2) };
-    let _x = b == dont_optimize(true); //~ ERROR interpreting an invalid 8-bit value as a bool: 0x02
+    let _x = b == std::hint::black_box(true); //~ ERROR interpreting an invalid 8-bit value as a bool: 0x02
 }
index ea6269c22fb98e836397ca5ea83ec0945205013e..327ea17731a8d6dfbdf3601a41e378103aadeab9 100644 (file)
@@ -1,7 +1,8 @@
 // compile-flags: -Zmir-opt-level=0
 // FIXME: Using opt-level 2 here makes the test take forever (https://github.com/rust-lang/rust/issues/76433).
-#![feature(stmt_expr_attributes)]
+#![feature(stmt_expr_attributes, test)]
 use std::fmt::Debug;
+use std::hint::black_box;
 
 // Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
 // Doesn't make a big difference when running this in Miri, but it means we can compare this
@@ -341,10 +342,6 @@ fn ops() {
 /// Tests taken from rustc test suite.
 ///
 
-// Poor-man's black-box
-#[inline(never)]
-fn black_box<T>(x: T) -> T { x }
-
 macro_rules! test {
     ($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => (
         // black_box disables constant evaluation to test run-time conversions:
index a2ca7746b1c05148edb8a054c0337c8b0eed1ef9..bbc667c5ddebb74229dceb8dd0eb9462e045f3a7 100644 (file)
@@ -1,4 +1,5 @@
-fn b<T>(t: T) -> T { t }
+#![feature(test)]
+use std::hint::black_box as b;
 
 fn main() {
     let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF;