remove the tiny bit of unsafe code

This commit is contained in:
James McGlashan 2020-01-17 00:00:00 +00:00
parent dfa321a1dd
commit 2a351016ed
No known key found for this signature in database
GPG Key ID: C2062B23665983D5
2 changed files with 3 additions and 3 deletions

View File

@ -120,6 +120,7 @@
)
)]
// Rustc lints.
#![forbid(unsafe_code)]
#![deny(missing_docs, unused_imports)]
////////////////////////////////////////////////////////////////////////////////

View File

@ -633,8 +633,7 @@ impl Serialize for SystemTime {
#[cfg(feature = "std")]
macro_rules! serialize_display_bounded_length {
($value:expr, $max:expr, $serializer:expr) => {{
#[allow(deprecated)]
let mut buffer: [u8; $max] = unsafe { mem::uninitialized() };
let mut buffer: [u8; $max] = [0u8; $max];
let remaining_len = {
let mut remaining = &mut buffer[..];
write!(remaining, "{}", $value).unwrap();
@ -646,7 +645,7 @@ macro_rules! serialize_display_bounded_length {
// write! only provides fmt::Formatter to Display implementations, which
// has methods write_str and write_char but no method to write arbitrary
// bytes. Therefore `written` must be valid UTF-8.
let written_str = unsafe { str::from_utf8_unchecked(written) };
let written_str = str::from_utf8(written).expect("must be valid UTF-8");
$serializer.serialize_str(written_str)
}};
}