File tree 2 files changed +13
-1
lines changed
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> {
23
23
#[ must_use]
24
24
pub ( super ) const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
25
25
// 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) } }
27
27
}
28
28
29
29
#[ 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> {
1811
1811
}
1812
1812
}
1813
1813
}
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
+ }
1814
1826
1815
1827
impl < T , U > Option < ( T , U ) > {
1816
1828
/// Unzips an option containing a tuple of two options.
You can’t perform that action at this time.
0 commit comments