File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use crate::char::TryFromCharError;
4
4
use crate :: convert:: TryFrom ;
5
5
use crate :: error:: Error ;
6
6
use crate :: fmt;
7
+ use crate :: intrinsics:: assert_unsafe_precondition;
7
8
use crate :: mem:: transmute;
8
9
use crate :: str:: FromStr ;
9
10
@@ -23,7 +24,13 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
23
24
#[ must_use]
24
25
pub ( super ) const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
25
26
// 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) } }
27
+ unsafe {
28
+ assert_unsafe_precondition ! (
29
+ "invalid value for `char`" ,
30
+ ( i: u32 ) => char_try_from_u32( i) . is_ok( )
31
+ ) ;
32
+ transmute ( i)
33
+ }
27
34
}
28
35
29
36
#[ stable( feature = "char_convert" , since = "1.13.0" ) ]
You can’t perform that action at this time.
0 commit comments