about summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-26 04:10:54 +0000
committerbors <bors@rust-lang.org>2019-08-26 04:10:54 +0000
commite2b4165a6c2fbab4c1bde97d0c2e47b4602f7bc0 (patch)
treeb8497775c78ef5bff55599fb4e6acd94b357cc5f /src/libstd/sys/unix/stack_overflow.rs
parent4c58535d09d1261d21569df0036b974811544256 (diff)
parenta4b3dbe4c1b225b4b911438861e98e4b1aa70183 (diff)
downloadrust-e2b4165a6c2fbab4c1bde97d0c2e47b4602f7bc0.tar.gz
rust-e2b4165a6c2fbab4c1bde97d0c2e47b4602f7bc0.zip
Auto merge of #62891 - vext01:improve-black-box-docs, r=RalfJung,Centril,gnzlbg
Improve the documentation for std::hint::black_box.

The other day a colleague was reviewing some of my code which was using `black_box` to block constant propogation. There was a little confusion because the documentation kind of implies that `black_box` is only useful for dead code elimination, and only in benchmarking scenarios.

The docs currently say:

> A function that is opaque to the optimizer, to allow benchmarks to pretend to use outputs to assist in avoiding dead-code elimination.

Here is our discussion, in which I show (using godbolt) that a black box can also block constant propagation:
https://github.com/softdevteam/yk/pull/21#discussion_r302985038

This change makes the docstring for `black_box` a little more general, and while we are here, I've added an example (the same one from our discussion).

![image](https://user-images.githubusercontent.com/604955/61701322-ddf1e400-ad35-11e9-878c-b5b44a20770c.png)

OK to go in?
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions