Rollup merge of #148333 - bend-n:const_result_unwrap_unchecked, r=mark-simulacrum
constify result unwrap unchecked constifies unwrap unchecked on result will make tracking issue if good
This commit is contained in:
commit
020dd317db
1 changed files with 8 additions and 3 deletions
|
|
@ -1646,11 +1646,16 @@ impl<T, E> Result<T, E> {
|
|||
#[inline]
|
||||
#[track_caller]
|
||||
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
|
||||
pub unsafe fn unwrap_unchecked(self) -> T {
|
||||
#[rustc_const_unstable(feature = "const_result_unwrap_unchecked", issue = "148714")]
|
||||
pub const unsafe fn unwrap_unchecked(self) -> T {
|
||||
match self {
|
||||
Ok(t) => t,
|
||||
// SAFETY: the safety contract must be upheld by the caller.
|
||||
Err(_) => unsafe { hint::unreachable_unchecked() },
|
||||
Err(e) => {
|
||||
// FIXME(const-hack): to avoid E: const Destruct bound
|
||||
super::mem::forget(e);
|
||||
// SAFETY: the safety contract must be upheld by the caller.
|
||||
unsafe { hint::unreachable_unchecked() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue