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
This is a tracking issue for the unchecked variants of unwrap() and unwrap_err() of Option and Result.
These are unsafe functions intended to be used in hot paths of performance sensitive applications where the variant an Option/Result holds is known, allowing to skip the branch that the safe version introduces. They complement other *_unchecked() methods already available, such as get_unchecked() in slices.
It seems best to have it under another feature flag to avoid blocking this one.
Should we panic on failure in debug (i.e. for those projects that build core themselves)? If yes, that would mean there is no way to actually remove the check for those projects, which could be potentially needed by someone. If we do, should it be documented? Tracking Issue for option_result_unwrap_unchecked #81383 (comment)
The current implementation uses debug_assert!, which may be useful for projects that build core with debug assertions enabled (e.g. the bors test suite or some embedded projects), but this is not documented, and indeed most users will not see such behavior, since core is shipped in release mode.
Furthermore, since it is UB anyway, we have room for changing the implementation, e.g. if we end up distributing the standard library with debug assertions enabled for some use cases.
On the other hand, the unchecked_{add,...} methods seem to follow the opposite convention, but those are unstable and they likely do it because the stable {checked,...}_{add,...} exist.
Feature gate:
#![feature(option_result_unwrap_unchecked)]This is a tracking issue for the unchecked variants of
unwrap()andunwrap_err()ofOptionandResult.These are unsafe functions intended to be used in hot paths of performance sensitive applications where the variant an
Option/Resultholds is known, allowing to skip the branch that the safe version introduces. They complement other*_unchecked()methods already available, such asget_unchecked()in slices.Public API
Steps / History
unwrap_unchecked()methods forOptionandResult#80876option_result_unwrap_unchecked#81383 (comment)option_result_unwrap_unchecked#81383 (comment)option_result_unwrap_unchecked#89951Unresolved Questions
Should we add
expect_unchecked, and if yes, do it within another feature flag, to unblockunwrap_unchecked? Tracking Issue foroption_result_unwrap_unchecked#81383 (comment)Should we panic on failure in debug (i.e. for those projects that build
corethemselves)? If yes, that would mean there is no way to actually remove the check for those projects, which could be potentially needed by someone. If we do, should it be documented? Tracking Issue foroption_result_unwrap_unchecked#81383 (comment)debug_assert!, which may be useful for projects that buildcorewith debug assertions enabled (e.g. the bors test suite or some embedded projects), but this is not documented, and indeed most users will not see such behavior, sincecoreis shipped in release mode.Should we name them
unchecked_unwrapinstead? Tracking Issue foroption_result_unwrap_unchecked#81383 (comment).unwrap_unchecked) follows the convention of other stable methods in the standard library such asget_unchecked,map_unchecked,new_unchecked,unreachable_unchecked... (see as well https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter).unchecked_{add,...}methods seem to follow the opposite convention, but those are unstable and they likely do it because the stable{checked,...}_{add,...}exist.