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 9 pub trait UncheckedOptionExt<T> { unchecked_unwrap(self) -> T10 unsafe fn unchecked_unwrap(self) -> T; 11 } 12 13 impl<T> UncheckedOptionExt<T> for Option<T> { 14 #[inline] unchecked_unwrap(self) -> T15 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] unreachable() -> !25unsafe fn unreachable() -> ! { 26 if cfg!(debug_assertions) { 27 unreachable!(); 28 } else { 29 core::hint::unreachable_unchecked() 30 } 31 } 32