@@ -396,9 +396,8 @@ pub fn spin_loop() {
396
396
///
397
397
/// In practice, `black_box` serves two purposes:
398
398
///
399
- /// 1. It prevents the compiler from making optimizations related to the value of the returned
400
- /// type
401
- /// 2. It forces the input to be calculated, even if its results are never used
399
+ /// 1. It prevents the compiler from making optimizations related to the value returned by `black_box`
400
+ /// 2. It forces the value passed to `black_box` to be calculated, even if the return value of `black_box` is unused
402
401
///
403
402
/// ```
404
403
/// use std::hint::black_box;
@@ -407,11 +406,10 @@ pub fn spin_loop() {
407
406
/// let five = 5;
408
407
///
409
408
/// // The compiler will see this and remove the `* five` call, because it knows that multiplying
410
- /// // any integer by 0 will result in 0. This is a value optimization: the compiler knows the
411
- /// // value of `zero` must be 0, and thus can make optimizations related to that.
409
+ /// // any integer by 0 will result in 0.
412
410
/// let c = zero * five;
413
411
///
414
- /// // Adding `black_box` here disables the compiler's ability to reason about the value of `zero` .
412
+ /// // Adding `black_box` here disables the compiler's ability to reason about the first operand in the multiplication .
415
413
/// // It is forced to assume that it can be any possible number, so it cannot remove the `* five`
416
414
/// // operation.
417
415
/// let c = black_box(zero) * five;
@@ -444,7 +442,7 @@ pub fn spin_loop() {
444
442
///
445
443
/// There may be additional situations where you want to wrap the result of a function in
446
444
/// `black_box` to force its execution. This is situational though, and may not have any effect
447
- /// (such as when the function returns a [`()` unit][unit]).
445
+ /// (such as when the function returns a zero-sized type such as [`()` unit][unit]).
448
446
///
449
447
/// Note that `black_box` has no effect on how its input is treated, only its output. As such,
450
448
/// expressions passed to `black_box` may still be optimized:
@@ -467,7 +465,7 @@ pub fn spin_loop() {
467
465
/// ```
468
466
/// use std::hint::black_box;
469
467
///
470
- /// // No assumptions can be made about either number , so the multiplication is kept .
468
+ /// // No assumptions can be made about either operand , so the multiplication is not optimized out .
471
469
/// let y = black_box(5) * black_box(10);
472
470
/// ```
473
471
#[ inline]
0 commit comments