You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given that this is likely often the case for simple inputs (particularly for arithemtic operations like the example), I was wondering if it would be good to have some kind of note in the documentation to advising that this function should only be used if it's actually necessary. In particular, this could note that rustc with -C opt-level=1 will produce the same assembly for the example as a version that uses unwrap instead.
Of course several caveats apply (it's not ideal to rely on compiler optimizations in docs, etc) - but IMO it could be worthwhile for the purpose of discouraging unecessary unsafe.
The text was updated successfully, but these errors were encountered:
Expand core::hint::unreachable_unchecked() docs
Rework the docs for `unreachable_unchecked`, encouraging deliberate use, and providing a better example for action at a distance.
Fixesrust-lang#95865
I don't know whether this is something that the docs team already has a particular policy on, so perhaps this is out of scope, but:
The docs for
std::hint::unreachable_unchecked
give an example that -- with optimizations -- compiles to the same assembly using plainunwrap
instead ofunwrap_or_else(|| unsafe { unreachable_unchecked })
. (See: https://godbolt.org/z/4ha9K1rGK)Given that this is likely often the case for simple inputs (particularly for arithemtic operations like the example), I was wondering if it would be good to have some kind of note in the documentation to advising that this function should only be used if it's actually necessary. In particular, this could note that rustc with
-C opt-level=1
will produce the same assembly for the example as a version that usesunwrap
instead.Of course several caveats apply (it's not ideal to rely on compiler optimizations in docs, etc) - but IMO it could be worthwhile for the purpose of discouraging unecessary unsafe.
The text was updated successfully, but these errors were encountered: