We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 96df494 commit ab716d0Copy full SHA for ab716d0
library/core/src/char/convert.rs
@@ -4,6 +4,7 @@ use crate::char::TryFromCharError;
4
use crate::convert::TryFrom;
5
use crate::error::Error;
6
use crate::fmt;
7
+use crate::intrinsics::assert_unsafe_precondition;
8
use crate::mem::transmute;
9
use crate::str::FromStr;
10
@@ -23,7 +24,13 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
23
24
#[must_use]
25
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
26
// SAFETY: the caller must guarantee that `i` is a valid char value.
- 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
+ }
34
}
35
36
#[stable(feature = "char_convert", since = "1.13.0")]
0 commit comments