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:
Stuart Cook 2025-11-09 13:22:29 +11:00 committed by GitHub
commit 020dd317db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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() }
}
}
}