movable_ref/pointer/
unreachable.rs

1pub(crate) const OVERFLOW_SUB: &str =
2    "Attempted to subtract with overflow, this is UB in release mode!";
3
4/// Adds an unchecked unwrap, this unwrap is UB if self is None
5///
6/// # Safety
7///
8/// This is UB if self is None and debug assertions are enabled
9pub(crate) trait UncheckedOptionExt {
10    type T;
11
12    unsafe fn unchecked_unwrap(self, err: &str) -> Self::T;
13}
14
15impl<T> UncheckedOptionExt for Option<T> {
16    type T = T;
17
18    #[inline]
19    #[allow(clippy::assertions_on_constants)]
20    unsafe fn unchecked_unwrap(self, err: &str) -> T {
21        match self {
22            Some(value) => value,
23            None if cfg!(debug_assertions) => panic!("{}", err),
24            None => std::hint::unreachable_unchecked(),
25        }
26    }
27}