Skip to content

Commit 3ba1035

Browse files
committed
use standard black_box function
1 parent 029c851 commit 3ba1035

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

tests/compile-fail/invalid_bool.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Validation makes this fail in the wrong place
22
// Make sure we find these even with many checks disabled.
33
// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
4-
5-
#[inline(never)]
6-
fn dont_optimize<T>(x: T) -> T { x }
4+
#![feature(test)]
75

86
fn main() {
97
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
10-
let _x = b == dont_optimize(true); //~ ERROR interpreting an invalid 8-bit value as a bool: 0x02
8+
let _x = b == std::hint::black_box(true); //~ ERROR interpreting an invalid 8-bit value as a bool: 0x02
119
}

tests/run-pass/float.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// compile-flags: -Zmir-opt-level=0
22
// FIXME: Using opt-level 2 here makes the test take forever (https://github.com/rust-lang/rust/issues/76433).
3-
#![feature(stmt_expr_attributes)]
3+
#![feature(stmt_expr_attributes, test)]
44
use std::fmt::Debug;
5+
use std::hint::black_box;
56

67
// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
78
// Doesn't make a big difference when running this in Miri, but it means we can compare this
@@ -341,10 +342,6 @@ fn ops() {
341342
/// Tests taken from rustc test suite.
342343
///
343344
344-
// Poor-man's black-box
345-
#[inline(never)]
346-
fn black_box<T>(x: T) -> T { x }
347-
348345
macro_rules! test {
349346
($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => (
350347
// black_box disables constant evaluation to test run-time conversions:

tests/run-pass/u128.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
fn b<T>(t: T) -> T { t }
1+
#![feature(test)]
2+
use std::hint::black_box as b;
23

34
fn main() {
45
let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF;

0 commit comments

Comments
 (0)