1// Copyright 2016 Amanieu d'Antras
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8// Option::unchecked_unwrap
9pub trait UncheckedOptionExt<T> {
10 unsafe fn unchecked_unwrap(self) -> T;
11}
12
13impl<T> UncheckedOptionExt<T> for Option<T> {
14 #[inline]
15 unsafe fn unchecked_unwrap(self) -> T {
16 match self {
17 Some(x) => x,
18 None => unreachable(),
19 }
20 }
21}
22
23// hint::unreachable_unchecked() in release mode
24#[inline]
25unsafe fn unreachable() -> ! {
26 if cfg!(debug_assertions) {
27 unreachable!();
28 } else {
29 core::hint::unreachable_unchecked()
30 }
31}
32