core: fix deprecated warnings
This commit is contained in:
parent
7bb5b3eb32
commit
851acdd22d
5 changed files with 40 additions and 44 deletions
|
@ -22,7 +22,7 @@ use ops::CoerceUnsized;
|
|||
use fmt;
|
||||
use hash;
|
||||
use marker::{PhantomData, Unsize};
|
||||
use mem;
|
||||
use mem::{self, MaybeUninit};
|
||||
use nonzero::NonZero;
|
||||
|
||||
use cmp::Ordering::{self, Less, Equal, Greater};
|
||||
|
@ -142,16 +142,12 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
|
||||
// Give ourselves some scratch space to work with
|
||||
let mut tmp: T = mem::uninitialized();
|
||||
let mut tmp = MaybeUninit::<T>::uninitialized();
|
||||
|
||||
// Perform the swap
|
||||
copy_nonoverlapping(x, &mut tmp, 1);
|
||||
copy_nonoverlapping(x, tmp.get_mut(), 1);
|
||||
copy(y, x, 1); // `x` and `y` may overlap
|
||||
copy_nonoverlapping(&tmp, y, 1);
|
||||
|
||||
// y and t now point to the same thing, but we need to completely forget `tmp`
|
||||
// because it's no longer relevant.
|
||||
mem::forget(tmp);
|
||||
copy_nonoverlapping(tmp.get_ref(), y, 1);
|
||||
}
|
||||
|
||||
/// Swaps a sequence of values at two mutable locations of the same type.
|
||||
|
@ -224,8 +220,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
|
|||
while i + block_size <= len {
|
||||
// Create some uninitialized memory as scratch space
|
||||
// Declaring `t` here avoids aligning the stack when this loop is unused
|
||||
let mut t: Block = mem::uninitialized();
|
||||
let t = &mut t as *mut _ as *mut u8;
|
||||
let mut t = mem::MaybeUninit::<Block>::uninitialized();
|
||||
let t = t.as_mut_ptr() as *mut u8;
|
||||
let x = x.add(i);
|
||||
let y = y.add(i);
|
||||
|
||||
|
@ -239,10 +235,10 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
|
|||
|
||||
if i < len {
|
||||
// Swap any remaining bytes
|
||||
let mut t: UnalignedBlock = mem::uninitialized();
|
||||
let mut t = mem::MaybeUninit::<UnalignedBlock>::uninitialized();
|
||||
let rem = len - i;
|
||||
|
||||
let t = &mut t as *mut _ as *mut u8;
|
||||
let t = t.as_mut_ptr() as *mut u8;
|
||||
let x = x.add(i);
|
||||
let y = y.add(i);
|
||||
|
||||
|
@ -296,9 +292,9 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
|
|||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub unsafe fn read<T>(src: *const T) -> T {
|
||||
let mut tmp: T = mem::uninitialized();
|
||||
copy_nonoverlapping(src, &mut tmp, 1);
|
||||
tmp
|
||||
let mut tmp = MaybeUninit::<T>::uninitialized();
|
||||
copy_nonoverlapping(src, tmp.get_mut(), 1);
|
||||
tmp.into_inner()
|
||||
}
|
||||
|
||||
/// Reads the value from `src` without moving it. This leaves the
|
||||
|
@ -330,11 +326,11 @@ pub unsafe fn read<T>(src: *const T) -> T {
|
|||
#[inline]
|
||||
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
|
||||
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
|
||||
let mut tmp: T = mem::uninitialized();
|
||||
let mut tmp = MaybeUninit::<T>::uninitialized();
|
||||
copy_nonoverlapping(src as *const u8,
|
||||
&mut tmp as *mut T as *mut u8,
|
||||
tmp.as_mut_ptr() as *mut u8,
|
||||
mem::size_of::<T>());
|
||||
tmp
|
||||
tmp.into_inner()
|
||||
}
|
||||
|
||||
/// Overwrites a memory location with the given value without reading or
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue