Skip to content

Commit

Permalink
Rollup merge of #72683 - RalfJung:char-debug-check, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
from_u32_unchecked: check validity when debug assertions are enabled
  • Loading branch information
Dylan-DPC authored May 29, 2020
2 parents 9279a6a + 52ed89a commit 793967b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libcore/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn from_u32(i: u32) -> Option<char> {
#[inline]
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
pub unsafe fn from_u32_unchecked(i: u32) -> char {
transmute(i)
if cfg!(debug_assertions) { char::from_u32(i).unwrap() } else { transmute(i) }
}

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

0 comments on commit 793967b

Please sign in to comment.