File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 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;
44use crate :: convert:: TryFrom ;
55use crate :: error:: Error ;
66use crate :: fmt;
7+ use crate :: intrinsics:: assert_unsafe_precondition;
78use crate :: mem:: transmute;
89use crate :: str:: FromStr ;
910
@@ -23,7 +24,13 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2324#[ must_use]
2425pub ( super ) const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
2526 // 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+ }
2734}
2835
2936#[ stable( feature = "char_convert" , since = "1.13.0" ) ]
You can’t perform that action at this time.
0 commit comments