File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2323#[ must_use]
2424pub ( super ) const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
2525 // SAFETY: the caller must guarantee that `i` is a valid char value.
26- if cfg ! ( debug_assertions) { char:: from_u32 ( i) . unwrap ( ) } else { unsafe { transmute ( i) } }
26+ if cfg ! ( debug_assertions) { char:: from_u32 ( i) . const_unwrap ( ) } else { unsafe { transmute ( i) } }
2727}
2828
2929#[ stable( feature = "char_convert" , since = "1.13.0" ) ]
Original file line number Diff line number Diff line change @@ -1811,6 +1811,18 @@ impl<T> Option<T> {
18111811 }
18121812 }
18131813}
1814+ impl < T : Copy > Option < T > {
1815+ /// Unwrap `Copy` types in a const context. Other than the `Copy` bounds,
1816+ /// this is the same as [`unwrap`][Option::unwrap].
1817+ #[ inline]
1818+ #[ track_caller]
1819+ pub ( crate ) const fn const_unwrap ( self ) -> T {
1820+ match self {
1821+ Some ( val) => val,
1822+ None => panic ( "called `Option::unwrap()` on a `None` value" ) ,
1823+ }
1824+ }
1825+ }
18141826
18151827impl < T , U > Option < ( T , U ) > {
18161828 /// Unzips an option containing a tuple of two options.
You can’t perform that action at this time.
0 commit comments