diff options
| author | bors <bors@rust-lang.org> | 2019-07-22 17:08:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-22 17:08:25 +0000 |
| commit | e649e903440bfd919bfc9db848c28df6d795a116 (patch) | |
| tree | d182bd52c502a10edf0c1f8dfd172f1081685ac2 /src/libcore | |
| parent | 4bc1ce7bdb7f5dc9ea07c0b630c087d8e11140e4 (diff) | |
| parent | 376382aff3e8dad93b273ce7e9231ec7946edbe0 (diff) | |
| download | rust-e649e903440bfd919bfc9db848c28df6d795a116.tar.gz rust-e649e903440bfd919bfc9db848c28df6d795a116.zip | |
Auto merge of #62873 - Centril:rollup-ncnuelj, r=Centril
Rollup of 14 pull requests Successful merges: - #62709 (Test that maplike FromIter satisfies uniqueness) - #62713 (Stabilize <*mut _>::cast and <*const _>::cast) - #62746 ( do not use assume_init in std::io) - #62787 (Fix typo in src/libstd/net/udp.rs doc comment) - #62788 (normalize use of backticks in compiler messages for libcore/ptr) - #62799 (use const array repeat expressions for uninit_array) - #62810 (normalize use of backticks in compiler messages for librustc_lint) - #62812 (normalize use of backticks in compiler messages for librustc_metadata) - #62832 (normalize use of backticks in compiler messages for librustc_incremental) - #62845 (read: fix doc comment) - #62853 (normalize use of backticks in compiler messages for librustc/hir) - #62854 (Fix typo in Unicode character name) - #62858 (Change wrong variable name.) - #62870 (fix lexing of comments with many \r) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/fmt/float.rs | 7 | ||||
| -rw-r--r-- | src/libcore/fmt/num.rs | 4 | ||||
| -rw-r--r-- | src/libcore/macros.rs | 23 | ||||
| -rw-r--r-- | src/libcore/mem/maybe_uninit.rs | 5 | ||||
| -rw-r--r-- | src/libcore/ptr/mod.rs | 4 | ||||
| -rw-r--r-- | src/libcore/ptr/unique.rs | 4 | ||||
| -rw-r--r-- | src/libcore/slice/sort.rs | 4 |
7 files changed, 37 insertions, 14 deletions
diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 4bd7d3b4b22..a2fff913ac7 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -12,10 +12,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T, unsafe { let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64 let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit(); - // FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized - // `MaybeUninit` (here and elsewhere in this file). Revisit this once + // FIXME(#53491): This is calling `get_mut` on an uninitialized + // `MaybeUninit` (here and elsewhere in this file). Revisit this once // we decided whether that is valid or not. - // Using `freeze` is *not enough*; `flt2dec::Part` is an enum! + // We can do this only because we are libstd and coupled to the compiler. + // (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!) let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact, *num, sign, precision, false, buf.get_mut(), parts.get_mut()); diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index f9b4c26496c..3b5c9fbff25 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -51,7 +51,7 @@ trait GenericRadix { // characters for a base 2 number. let zero = T::zero(); let is_nonnegative = x >= zero; - let mut buf = uninitialized_array![u8; 128]; + let mut buf = [MaybeUninit::<u8>::uninit(); 128]; let mut curr = buf.len(); let base = T::from_u8(Self::BASE); if is_nonnegative { @@ -189,7 +189,7 @@ static DEC_DIGITS_LUT: &[u8; 200] = macro_rules! impl_Display { ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => { fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut buf = uninitialized_array![u8; 39]; + let mut buf = [MaybeUninit::<u8>::uninit(); 39]; let mut curr = buf.len() as isize; let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf); let lut_ptr = DEC_DIGITS_LUT.as_ptr(); diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 293a2dd9492..296bb43f9fa 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -626,20 +626,37 @@ macro_rules! todo { /// Creates an array of [`MaybeUninit`]. /// /// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`. +/// It exists solely because bootstrap does not yet support const array-init expressions. /// /// [`MaybeUninit`]: mem/union.MaybeUninit.html +// FIXME: Remove both versions of this macro once bootstrap is 1.38. #[macro_export] #[unstable(feature = "maybe_uninit_array", issue = "53491")] -macro_rules! uninitialized_array { +#[cfg(bootstrap)] +macro_rules! uninit_array { // This `assume_init` is safe because an array of `MaybeUninit` does not // require initialization. - // FIXME(#49147): Could be replaced by an array initializer, once those can - // be any const expression. ($t:ty; $size:expr) => (unsafe { MaybeUninit::<[MaybeUninit<$t>; $size]>::uninit().assume_init() }); } +/// Creates an array of [`MaybeUninit`]. +/// +/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`. +/// It exists solely because bootstrap does not yet support const array-init expressions. +/// +/// [`MaybeUninit`]: mem/union.MaybeUninit.html +// FIXME: Just inline this version of the macro once bootstrap is 1.38. +#[macro_export] +#[unstable(feature = "maybe_uninit_array", issue = "53491")] +#[cfg(not(bootstrap))] +macro_rules! uninit_array { + ($t:ty; $size:expr) => ( + [MaybeUninit::<$t>::UNINIT; $size] + ); +} + /// Built-in macros to the compiler itself. /// /// These macros do not have any corresponding definition with a `macro_rules!` diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index f6f7ccffdb0..2e88db8df11 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -252,6 +252,11 @@ impl<T> MaybeUninit<T> { MaybeUninit { uninit: () } } + /// A promotable constant, equivalent to `uninit()`. + #[unstable(feature = "internal_uninit_const", issue = "0", + reason = "hack to work around promotability")] + pub const UNINIT: Self = Self::uninit(); + /// Creates a new `MaybeUninit<T>` in an uninitialized state, with the memory being /// filled with `0` bytes. It depends on `T` whether that already makes for /// proper initialization. For example, `MaybeUninit<usize>::zeroed()` is initialized, diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index df66a2978de..a7f6926de42 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1043,7 +1043,7 @@ impl<T: ?Sized> *const T { } /// Cast to a pointer to a different type - #[unstable(feature = "ptr_cast", issue = "60602")] + #[stable(feature = "ptr_cast", since = "1.38.0")] #[inline] pub const fn cast<U>(self) -> *const U { self as _ @@ -1678,7 +1678,7 @@ impl<T: ?Sized> *mut T { } /// Cast to a pointer to a different type - #[unstable(feature = "ptr_cast", issue = "60602")] + #[stable(feature = "ptr_cast", since = "1.38.0")] #[inline] pub const fn cast<U>(self) -> *mut U { self as _ diff --git a/src/libcore/ptr/unique.rs b/src/libcore/ptr/unique.rs index 5911518919e..d2517e51fc5 100644 --- a/src/libcore/ptr/unique.rs +++ b/src/libcore/ptr/unique.rs @@ -26,8 +26,8 @@ use crate::ptr::NonNull; /// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct /// for any type which upholds Unique's aliasing requirements. #[unstable(feature = "ptr_internals", issue = "0", - reason = "use NonNull instead and consider PhantomData<T> \ - (if you also use #[may_dangle]), Send, and/or Sync")] + reason = "use `NonNull` instead and consider `PhantomData<T>` \ + (if you also use `#[may_dangle]`), `Send`, and/or `Sync`")] #[doc(hidden)] #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] diff --git a/src/libcore/slice/sort.rs b/src/libcore/slice/sort.rs index c293b190018..2f2170f7ff1 100644 --- a/src/libcore/slice/sort.rs +++ b/src/libcore/slice/sort.rs @@ -216,14 +216,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_array![u8; BLOCK]; + let mut offsets_l = [MaybeUninit::<u8>::uninit(); BLOCK]; // 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_array![u8; BLOCK]; + let mut offsets_r = [MaybeUninit::<u8>::uninit(); BLOCK]; // 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. |
