Skip to content

Commit 52ed89a

Browse files
committedMay 28, 2020
from_u32_unchecked: check validity when debug assertions are enabled
1 parent 4512721 commit 52ed89a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

‎src/libcore/char/convert.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn from_u32(i: u32) -> Option<char> {
9999
#[inline]
100100
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
101101
pub unsafe fn from_u32_unchecked(i: u32) -> char {
102-
transmute(i)
102+
if cfg!(debug_assertions) { char::from_u32(i).unwrap() } else { transmute(i) }
103103
}
104104

105105
#[stable(feature = "char_convert", since = "1.13.0")]
@@ -218,7 +218,7 @@ impl TryFrom<u32> for char {
218218
Err(CharTryFromError(()))
219219
} else {
220220
// SAFETY: checked that it's a legal unicode value
221-
Ok(unsafe { from_u32_unchecked(i) })
221+
Ok(unsafe { transmute(i) })
222222
}
223223
}
224224
}

0 commit comments

Comments
 (0)
Please sign in to comment.