Skip to content

Commit ec2d59d

Browse files
committed
Merge pull request #20463 from amaranth/black_box_output
[r+] Return passed value from black_box Reviewed-by: alexcrichton
2 parents 587598e + 9f5fc56 commit ec2d59d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/libcollections/bit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,7 @@ mod bitv_bench {
25262526
for _ in range(0u, 100) {
25272527
bitv |= 1 << ((r.next_u32() as uint) % u32::BITS);
25282528
}
2529-
black_box(&bitv)
2529+
black_box(&bitv);
25302530
});
25312531
}
25322532

@@ -2538,7 +2538,7 @@ mod bitv_bench {
25382538
for _ in range(0u, 100) {
25392539
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
25402540
}
2541-
black_box(&bitv)
2541+
black_box(&bitv);
25422542
});
25432543
}
25442544

src/libcollections/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,7 @@ mod bench {
28412841
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
28422842

28432843
b.iter(|| {
2844-
for ch in s.chars() { black_box(ch) }
2844+
for ch in s.chars() { black_box(ch); }
28452845
});
28462846
}
28472847

@@ -2869,7 +2869,7 @@ mod bench {
28692869
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
28702870

28712871
b.iter(|| {
2872-
for ch in s.chars().rev() { black_box(ch) }
2872+
for ch in s.chars().rev() { black_box(ch); }
28732873
});
28742874
}
28752875

src/libtest/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,10 +1332,11 @@ impl MetricMap {
13321332
/// elimination.
13331333
///
13341334
/// This function is a no-op, and does not even read from `dummy`.
1335-
pub fn black_box<T>(dummy: T) {
1335+
pub fn black_box<T>(dummy: T) -> T {
13361336
// we need to "use" the argument in some way LLVM can't
13371337
// introspect.
13381338
unsafe {asm!("" : : "r"(&dummy))}
1339+
dummy
13391340
}
13401341

13411342

0 commit comments

Comments
 (0)