Skip to content

Commit 218883a

Browse files
ChrisDentonjoboet
andauthored
Update library/core/src/char/convert.rs
Co-authored-by: joboet <[email protected]>
1 parent a207bf0 commit 218883a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/core/src/char/convert.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2323
#[must_use]
2424
pub(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).const_unwrap() } else { unsafe { transmute(i) } }
26+
unsafe {
27+
assert_unsafe_precondition!(
28+
"invalid value for `char`",
29+
(i: u32) => char_try_from_u32(i).is_ok()
30+
);
31+
transmute(i)
32+
}
2733
}
2834

2935
#[stable(feature = "char_convert", since = "1.13.0")]

0 commit comments

Comments
 (0)