From 3ba1035d279e0acfc3aaf68e8bd055f2d1ffb205 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 7 Sep 2020 11:26:24 +0200 Subject: [PATCH] use standard black_box function --- tests/compile-fail/invalid_bool.rs | 6 ++---- tests/run-pass/float.rs | 7 ++----- tests/run-pass/u128.rs | 3 ++- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/compile-fail/invalid_bool.rs b/tests/compile-fail/invalid_bool.rs index 8d8cce1c7e5..796d8220dc1 100644 --- a/tests/compile-fail/invalid_bool.rs +++ b/tests/compile-fail/invalid_bool.rs @@ -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(x: T) -> T { x } +#![feature(test)] fn main() { let b = unsafe { std::mem::transmute::(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 } diff --git a/tests/run-pass/float.rs b/tests/run-pass/float.rs index ea6269c22fb..327ea17731a 100644 --- a/tests/run-pass/float.rs +++ b/tests/run-pass/float.rs @@ -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(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: diff --git a/tests/run-pass/u128.rs b/tests/run-pass/u128.rs index a2ca7746b1c..bbc667c5dde 100644 --- a/tests/run-pass/u128.rs +++ b/tests/run-pass/u128.rs @@ -1,4 +1,5 @@ -fn b(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; -- 2.44.0