@@ -396,9 +396,8 @@ pub fn spin_loop() {
396396///
397397/// In practice, `black_box` serves two purposes:
398398///
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
402401///
403402/// ```
404403/// use std::hint::black_box;
@@ -407,11 +406,10 @@ pub fn spin_loop() {
407406/// let five = 5;
408407///
409408/// // 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.
412410/// let c = zero * five;
413411///
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 .
415413/// // It is forced to assume that it can be any possible number, so it cannot remove the `* five`
416414/// // operation.
417415/// let c = black_box(zero) * five;
@@ -444,7 +442,7 @@ pub fn spin_loop() {
444442///
445443/// There may be additional situations where you want to wrap the result of a function in
446444/// `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]).
448446///
449447/// Note that `black_box` has no effect on how its input is treated, only its output. As such,
450448/// expressions passed to `black_box` may still be optimized:
@@ -467,7 +465,7 @@ pub fn spin_loop() {
467465/// ```
468466/// use std::hint::black_box;
469467///
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 .
471469/// let y = black_box(5) * black_box(10);
472470/// ```
473471#[ inline]
0 commit comments