diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 41bc0a01..286d5dd6 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -120,6 +120,7 @@ ) )] // Rustc lints. +#![forbid(unsafe_code)] #![deny(missing_docs, unused_imports)] //////////////////////////////////////////////////////////////////////////////// diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 0ac667db..e7eece28 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -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) }}; }