diff options
| author | Michael Bradshaw <mjbshaw@google.com> | 2018-09-29 19:51:09 -0700 |
|---|---|---|
| committer | Michael Bradshaw <mjbshaw@google.com> | 2018-09-29 19:51:09 -0700 |
| commit | 43cc32fbb2506eff0090e894c1e8a46b62a8eb0b (patch) | |
| tree | ac301fe1be819c25d833880da0ab32bf550016eb /src/libcore | |
| parent | aec5330082a0c4664abf0f6604c1b05768a90234 (diff) | |
| parent | 9653f790333d1270f36f1614e85d8a7b54193e75 (diff) | |
| download | rust-43cc32fbb2506eff0090e894c1e8a46b62a8eb0b.tar.gz rust-43cc32fbb2506eff0090e894c1e8a46b62a8eb0b.zip | |
Merge branch 'master' into drop
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/fmt/float.rs | 27 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 2 | ||||
| -rw-r--r-- | src/libcore/pin.rs | 10 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 32 | ||||
| -rw-r--r-- | src/libcore/slice/rotate.rs | 12 | ||||
| -rw-r--r-- | src/libcore/slice/sort.rs | 14 |
6 files changed, 52 insertions, 45 deletions
diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index d01cd012031..03e7a9a49d8 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -9,7 +9,7 @@ // except according to those terms. use fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug}; -use mem::MaybeUninit; +use mem; use num::flt2dec; // Don't inline this so callers don't use the stack space this function @@ -20,11 +20,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T, where T: flt2dec::DecodableFloat { unsafe { - let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 - let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized(); + let mut buf: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64 + let mut parts: [flt2dec::Part; 4] = mem::uninitialized(); let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact, *num, sign, precision, - false, buf.get_mut(), parts.get_mut()); + false, &mut buf, &mut parts); fmt.pad_formatted_parts(&formatted) } } @@ -38,11 +38,10 @@ fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter, num: &T, { unsafe { // enough for f32 and f64 - let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); - let mut parts = MaybeUninit::<[flt2dec::Part; 4]>::uninitialized(); + let mut buf: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized(); + let mut parts: [flt2dec::Part; 4] = mem::uninitialized(); let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num, - sign, precision, false, buf.get_mut(), - parts.get_mut()); + sign, precision, false, &mut buf, &mut parts); fmt.pad_formatted_parts(&formatted) } } @@ -76,11 +75,11 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter, num: &T, where T: flt2dec::DecodableFloat { unsafe { - let mut buf = MaybeUninit::<[u8; 1024]>::uninitialized(); // enough for f32 and f64 - let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized(); + let mut buf: [u8; 1024] = mem::uninitialized(); // enough for f32 and f64 + let mut parts: [flt2dec::Part; 6] = mem::uninitialized(); let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact, *num, sign, precision, - upper, buf.get_mut(), parts.get_mut()); + upper, &mut buf, &mut parts); fmt.pad_formatted_parts(&formatted) } } @@ -95,11 +94,11 @@ fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter, { unsafe { // enough for f32 and f64 - let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninitialized(); - let mut parts = MaybeUninit::<[flt2dec::Part; 6]>::uninitialized(); + let mut buf: [u8; flt2dec::MAX_SIG_DIGITS] = mem::uninitialized(); + let mut parts: [flt2dec::Part; 6] = mem::uninitialized(); let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest, *num, sign, (0, 0), upper, - buf.get_mut(), parts.get_mut()); + &mut buf, &mut parts); fmt.pad_formatted_parts(&formatted) } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 3b7646fa268..675e73e952c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -246,8 +246,6 @@ macro_rules! test_v512 { ($item:item) => {}; } #[allow(unused_macros)] macro_rules! vector_impl { ($([$f:ident, $($args:tt)*]),*) => { $($f!($($args)*);)* } } #[path = "../stdsimd/coresimd/mod.rs"] -// replacing uses of mem::{uninitialized,zeroed} with MaybeUninit needs to be in the stdsimd repo -#[allow(deprecated)] #[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)] #[unstable(feature = "stdsimd", issue = "48556")] #[cfg(not(stage0))] // allow changes to how stdsimd works in stage0 diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index d09a545aecf..0224560af4c 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -293,21 +293,21 @@ where } #[unstable(feature = "pin", issue = "49150")] -impl<'a, P: fmt::Debug> fmt::Debug for Pin<P> { +impl<P: fmt::Debug> fmt::Debug for Pin<P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.pointer, f) } } #[unstable(feature = "pin", issue = "49150")] -impl<'a, P: fmt::Display> fmt::Display for Pin<P> { +impl<P: fmt::Display> fmt::Display for Pin<P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.pointer, f) } } #[unstable(feature = "pin", issue = "49150")] -impl<'a, P: fmt::Pointer> fmt::Pointer for Pin<P> { +impl<P: fmt::Pointer> fmt::Pointer for Pin<P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Pointer::fmt(&self.pointer, f) } @@ -319,10 +319,10 @@ impl<'a, P: fmt::Pointer> fmt::Pointer for Pin<P> { // for other reasons, though, so we just need to take care not to allow such // impls to land in std. #[unstable(feature = "pin", issue = "49150")] -impl<'a, P, U> CoerceUnsized<Pin<U>> for Pin<P> +impl<P, U> CoerceUnsized<Pin<U>> for Pin<P> where P: CoerceUnsized<U>, {} #[unstable(feature = "pin", issue = "49150")] -impl<'a, P> Unpin for Pin<P> {} +impl<P> Unpin for Pin<P> {} diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index b23b72c3720..14f2148a64e 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -79,7 +79,7 @@ use ops::CoerceUnsized; use fmt; use hash; use marker::{PhantomData, Unsize}; -use mem::{self, MaybeUninit}; +use mem; use nonzero::NonZero; use cmp::Ordering::{self, Less, Equal, Greater}; @@ -294,12 +294,16 @@ 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 = MaybeUninit::<T>::uninitialized(); + let mut tmp: T = mem::uninitialized(); // Perform the swap - copy_nonoverlapping(x, tmp.as_mut_ptr(), 1); + copy_nonoverlapping(x, &mut tmp, 1); copy(y, x, 1); // `x` and `y` may overlap - copy_nonoverlapping(tmp.get_ref(), y, 1); + 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); } /// Swaps `count * size_of::<T>()` bytes between the two regions of memory @@ -386,8 +390,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 = mem::MaybeUninit::<Block>::uninitialized(); - let t = t.as_mut_ptr() as *mut u8; + let mut t: Block = mem::uninitialized(); + let t = &mut t as *mut _ as *mut u8; let x = x.add(i); let y = y.add(i); @@ -401,10 +405,10 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) { if i < len { // Swap any remaining bytes - let mut t = mem::MaybeUninit::<UnalignedBlock>::uninitialized(); + let mut t: UnalignedBlock = mem::uninitialized(); let rem = len - i; - let t = t.as_mut_ptr() as *mut u8; + let t = &mut t as *mut _ as *mut u8; let x = x.add(i); let y = y.add(i); @@ -569,9 +573,9 @@ pub unsafe fn replace<T>(dst: *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 = MaybeUninit::<T>::uninitialized(); - copy_nonoverlapping(src, tmp.as_mut_ptr(), 1); - tmp.into_inner() + let mut tmp: T = mem::uninitialized(); + copy_nonoverlapping(src, &mut tmp, 1); + tmp } /// Reads the value from `src` without moving it. This leaves the @@ -636,11 +640,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 = MaybeUninit::<T>::uninitialized(); + let mut tmp: T = mem::uninitialized(); copy_nonoverlapping(src as *const u8, - tmp.as_mut_ptr() as *mut u8, + &mut tmp as *mut T as *mut u8, mem::size_of::<T>()); - tmp.into_inner() + tmp } /// Overwrites a memory location with the given value without reading or diff --git a/src/libcore/slice/rotate.rs b/src/libcore/slice/rotate.rs index 07153735300..0d182b84974 100644 --- a/src/libcore/slice/rotate.rs +++ b/src/libcore/slice/rotate.rs @@ -9,7 +9,7 @@ // except according to those terms. use cmp; -use mem::{self, MaybeUninit}; +use mem; use ptr; /// Rotation is much faster if it has access to a little bit of memory. This @@ -26,6 +26,12 @@ union RawArray<T> { } impl<T> RawArray<T> { + fn new() -> Self { + unsafe { mem::uninitialized() } + } + fn ptr(&self) -> *mut T { + unsafe { &self.typed as *const T as *mut T } + } fn cap() -> usize { if mem::size_of::<T>() == 0 { usize::max_value() @@ -82,8 +88,8 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) { } } - let mut rawarray = MaybeUninit::<RawArray<T>>::uninitialized(); - let buf = &mut (*rawarray.as_mut_ptr()).typed as *mut [T; 2] as *mut T; + let rawarray = RawArray::new(); + let buf = rawarray.ptr(); let dim = mid.sub(left).add(right); if left <= right { diff --git a/src/libcore/slice/sort.rs b/src/libcore/slice/sort.rs index affe84fbef9..e4c1fd03f9e 100644 --- a/src/libcore/slice/sort.rs +++ b/src/libcore/slice/sort.rs @@ -17,7 +17,7 @@ //! stable sorting implementation. use cmp; -use mem::{self, MaybeUninit}; +use mem; use ptr; /// When dropped, copies from `src` into `dest`. @@ -226,14 +226,14 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize let mut block_l = BLOCK; let mut start_l = ptr::null_mut(); let mut end_l = ptr::null_mut(); - let mut offsets_l = MaybeUninit::<[u8; BLOCK]>::uninitialized(); + let mut offsets_l: [u8; BLOCK] = unsafe { mem::uninitialized() }; // The current block on the right side (from `r.sub(block_r)` to `r`). let mut r = unsafe { l.add(v.len()) }; let mut block_r = BLOCK; let mut start_r = ptr::null_mut(); let mut end_r = ptr::null_mut(); - let mut offsets_r = MaybeUninit::<[u8; BLOCK]>::uninitialized(); + let mut offsets_r: [u8; BLOCK] = unsafe { mem::uninitialized() }; // FIXME: When we get VLAs, try creating one array of length `min(v.len(), 2 * BLOCK)` rather // than two fixed-size arrays of length `BLOCK`. VLAs might be more cache-efficient. @@ -272,8 +272,8 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize if start_l == end_l { // Trace `block_l` elements from the left side. - start_l = offsets_l.as_mut_ptr() as *mut u8; - end_l = offsets_l.as_mut_ptr() as *mut u8; + start_l = offsets_l.as_mut_ptr(); + end_l = offsets_l.as_mut_ptr(); let mut elem = l; for i in 0..block_l { @@ -288,8 +288,8 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize if start_r == end_r { // Trace `block_r` elements from the right side. - start_r = offsets_r.as_mut_ptr() as *mut u8; - end_r = offsets_r.as_mut_ptr() as *mut u8; + start_r = offsets_r.as_mut_ptr(); + end_r = offsets_r.as_mut_ptr(); let mut elem = r; for i in 0..block_r { |
