Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of core::mem::uninitialized from ufmt. #306

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ufmt/src/impls/ixx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl uDebug for i8 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 4] = unsafe { crate::uninitialized() };
let mut buf: [u8; 4] = [0; 4];

f.write_str(isize(isize::from(*self), &mut buf))
}
Expand All @@ -69,7 +69,7 @@ impl uDebug for i16 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 6] = unsafe { crate::uninitialized() };
let mut buf: [u8; 6] = [0; 6];

f.write_str(isize(isize::from(*self), &mut buf))
}
Expand All @@ -90,7 +90,7 @@ impl uDebug for i32 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 11] = unsafe { crate::uninitialized() };
let mut buf: [u8; 11] = [0; 11];

f.write_str(isize(*self as isize, &mut buf))
}
Expand All @@ -112,7 +112,7 @@ impl uDebug for i64 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 20] = unsafe { crate::uninitialized() };
let mut buf: [u8; 20] = [0; 20];

let s = ixx!(u64, *self, buf);
f.write_str(s)
Expand All @@ -123,7 +123,7 @@ impl uDebug for i64 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 20] = unsafe { crate::uninitialized() };
let mut buf: [u8; 20] = [0; 20];

f.write_str(isize(*self as isize, &mut buf))
}
Expand All @@ -144,7 +144,7 @@ impl uDebug for i128 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 40] = unsafe { crate::uninitialized() };
let mut buf: [u8; 40] = [0; 40];

let s = ixx!(u128, *self, buf);
f.write_str(s)
Expand Down
2 changes: 1 addition & 1 deletion ufmt/src/impls/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{uDebug, uWrite, Formatter};

macro_rules! hex {
($self:expr, $f:expr, $N:expr) => {{
let mut buf: [u8; $N] = unsafe { crate::uninitialized() };
let mut buf: [u8; $N] = [0; $N];

let i = hex(*$self as usize, &mut buf);

Expand Down
12 changes: 6 additions & 6 deletions ufmt/src/impls/uxx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl uDebug for u8 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 3] = unsafe { crate::uninitialized() };
let mut buf: [u8; 3] = [0; 3];

f.write_str(usize(usize::from(*self), &mut buf))
}
Expand All @@ -53,7 +53,7 @@ impl uDebug for u16 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 5] = unsafe { crate::uninitialized() };
let mut buf: [u8; 5] = [0; 5];

f.write_str(usize(usize::from(*self), &mut buf))
}
Expand All @@ -74,7 +74,7 @@ impl uDebug for u32 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 10] = unsafe { crate::uninitialized() };
let mut buf: [u8; 10] = [0; 10];

f.write_str(usize(*self as usize, &mut buf))
}
Expand All @@ -96,7 +96,7 @@ impl uDebug for u64 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 20] = unsafe { crate::uninitialized() };
let mut buf: [u8; 20] = [0; 20];

let s = uxx!(*self, buf);
f.write_str(s)
Expand All @@ -107,7 +107,7 @@ impl uDebug for u64 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 20] = unsafe { crate::uninitialized() };
let mut buf: [u8; 20] = [0; 20];

f.write_str(usize(*self as usize, &mut buf))
}
Expand All @@ -128,7 +128,7 @@ impl uDebug for u128 {
where
W: uWrite + ?Sized,
{
let mut buf: [u8; 39] = unsafe { crate::uninitialized() };
let mut buf: [u8; 39] = [0; 39];

let s = uxx!(*self, buf);
f.write_str(s)
Expand Down
5 changes: 0 additions & 5 deletions ufmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ pub mod derive {
pub use ufmt_macros::uDebug;
}

#[allow(deprecated)]
unsafe fn uninitialized<T>() -> T {
core::mem::uninitialized()
}

/// Just like `core::fmt::Debug`
#[allow(non_camel_case_types)]
pub trait uDebug {
Expand Down
7 changes: 1 addition & 6 deletions ufmt/write/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
#[cfg(feature = "std")]
use core::convert::Infallible;

#[allow(deprecated)]
unsafe fn uninitialized<T>() -> T {
core::mem::uninitialized()
}

/// A collection of methods that are required / used to format a message into a stream.
#[allow(non_camel_case_types)]
pub trait uWrite {
Expand All @@ -32,7 +27,7 @@ pub trait uWrite {
/// entire byte sequence was successfully written, and this method will not return until all
/// data has been written or an error occurs.
fn write_char(&mut self, c: char) -> Result<(), Self::Error> {
let mut buf: [u8; 4] = unsafe { uninitialized() };
let mut buf: [u8; 4] = [0; 4];
self.write_str(c.encode_utf8(&mut buf))
}
}
Expand Down