Skip to content

Commit 05b1251

Browse files
committed
constify result unwrap unchecked
1 parent 51f5892 commit 05b1251

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

library/core/src/result.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,11 +1646,15 @@ impl<T, E> Result<T, E> {
16461646
#[inline]
16471647
#[track_caller]
16481648
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
1649-
pub unsafe fn unwrap_unchecked(self) -> T {
1649+
#[rustc_const_unstable(feature = "const_result_unwrap_unchecked", issue = "none")]
1650+
pub const unsafe fn unwrap_unchecked(self) -> T {
16501651
match self {
16511652
Ok(t) => t,
1652-
// SAFETY: the safety contract must be upheld by the caller.
1653-
Err(_) => unsafe { hint::unreachable_unchecked() },
1653+
Err(e) => {
1654+
super::mem::forget(e);
1655+
// SAFETY: the safety contract must be upheld by the caller.
1656+
unsafe { hint::unreachable_unchecked() }
1657+
}
16541658
}
16551659
}
16561660

0 commit comments

Comments
 (0)