Expand docs on std::hint::assert_unchecked - #161262
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
328a011 to
90204f5
Compare
There was a problem hiding this comment.
Language was introduced to the effect that UB may time-travel
Technically, UB probably does not today time travel - rust-lang/unsafe-code-guidelines#407... I don't know if structuring the language to suggest otherwise makes sense.
Language was introduced to the effect that a panic is guaranteed in debug mode
I think our current policy is that all ub checks are not guaranteed, so we shouldn't commit to that.
|
Reminder, once the PR becomes ready for a review, use |
|
I'll change the PR. Lets wait on rust-lang/reference#2320; once that commits, we can link to it |
This expands the documentation for
std::hint::assert_unchecked(). I tried to rework+expand some rather imprecise language ("simplify things", "UB", "quite unlike anything that would be used in the real world"), reworked the "good usage"-example to not rely on assembly to make its point, and added a "a bool may answer more than you asked for"-counter-example / too-narrow / too-broad. Most importantly for reviewassert_uncheckedis not guaranteed to be evaluated to the extend the programmer might expect from a bool; parts of the paragraph were aligned with theunreachable_uncheckeddocs.assert_uncheckedis not just a hint, as the argument needs to be evaluated before entering the function. So the question "How unchecked isunchecked?" can be answered to the effect that the compiler is not allowed to just completely ignore evaluatingcond; effects of evaluatingcondare guaranteed to be observed.ub_checks::assert_unsafe_precondition()should be guaranteed, but if it is, it is good to know for the reader.I checked that codegen for the examples actually produces what the examples demonstrate.
All tokens used in generating this PR were of purely biological nature.