diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 467ac401d086b..e3cdaaf989189 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -15,7 +15,7 @@ #![feature(extend_one)] #![feature(hash_raw_entry)] #![feature(hasher_prefixfree_extras)] -#![feature(maybe_uninit_uninit_array)] +#![feature(maybe_uninit_uninit_array_transpose)] #![feature(min_specialization)] #![feature(never_type)] #![feature(type_alias_impl_trait)] diff --git a/compiler/rustc_data_structures/src/sip128.rs b/compiler/rustc_data_structures/src/sip128.rs index 90793a97ed0d8..db496353d4615 100644 --- a/compiler/rustc_data_structures/src/sip128.rs +++ b/compiler/rustc_data_structures/src/sip128.rs @@ -183,7 +183,7 @@ impl SipHasher128 { pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher128 { let mut hasher = SipHasher128 { nbuf: 0, - buf: MaybeUninit::uninit_array(), + buf: MaybeUninit::uninit().transpose(), state: State { v0: key0 ^ 0x736f6d6570736575, // The XOR with 0xee is only done on 128-bit algorithm version. diff --git a/compiler/rustc_serialize/tests/leb128.rs b/compiler/rustc_serialize/tests/leb128.rs index 314c07db981da..2df6908bc49d3 100644 --- a/compiler/rustc_serialize/tests/leb128.rs +++ b/compiler/rustc_serialize/tests/leb128.rs @@ -1,5 +1,4 @@ -#![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_uninit_array)] +#![feature(maybe_uninit_uninit_array_transpose)] use rustc_serialize::leb128::*; use std::mem::MaybeUninit; @@ -24,7 +23,7 @@ macro_rules! impl_test_unsigned_leb128 { let mut stream = Vec::new(); for &x in &values { - let mut buf = MaybeUninit::uninit_array(); + let mut buf = MaybeUninit::uninit().transpose(); stream.extend($write_fn_name(&mut buf, x)); } @@ -70,7 +69,7 @@ macro_rules! impl_test_signed_leb128 { let mut stream = Vec::new(); for &x in &values { - let mut buf = MaybeUninit::uninit_array(); + let mut buf = MaybeUninit::uninit().transpose(); stream.extend($write_fn_name(&mut buf, x)); } diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 7fde8f670a231..95605f9f6c97f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -127,7 +127,7 @@ #![feature(layout_for_ptr)] #![feature(maybe_uninit_array_assume_init)] #![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_uninit_array)] +#![feature(maybe_uninit_uninit_array_transpose)] #![cfg_attr(test, feature(new_uninit))] #![feature(nonnull_slice_from_raw_parts)] #![feature(pattern)] diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 73d7c90cf78ec..c8d1e6ca31e31 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -210,7 +210,7 @@ impl Iterator for IntoIter { #[inline] fn next_chunk(&mut self) -> Result<[T; N], core::array::IntoIter> { - let mut raw_ary = MaybeUninit::uninit_array(); + let mut raw_ary = MaybeUninit::uninit().transpose(); let len = self.len(); diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index b3b2604006718..fe27aa6c17797 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -106,7 +106,6 @@ impl IntoIter { /// #![feature(array_into_iter_constructors)] /// /// #![feature(maybe_uninit_array_assume_init)] - /// #![feature(maybe_uninit_uninit_array)] /// use std::array::IntoIter; /// use std::mem::MaybeUninit; /// @@ -116,7 +115,7 @@ impl IntoIter { /// fn next_chunk( /// it: &mut impl Iterator, /// ) -> Result<[T; N], IntoIter> { - /// let mut buffer = MaybeUninit::uninit_array(); + /// let mut buffer = [MaybeUninit::uninit(); N]; /// let mut i = 0; /// while i < N { /// match it.next() { @@ -208,7 +207,7 @@ impl IntoIter { #[unstable(feature = "array_into_iter_constructors", issue = "91583")] #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const fn empty() -> Self { - let buffer = MaybeUninit::uninit_array(); + let buffer = MaybeUninit::uninit().transpose(); let initialized = 0..0; // SAFETY: We're telling it that none of the elements are initialized, @@ -387,7 +386,8 @@ impl Clone for IntoIter { fn clone(&self) -> Self { // Note, we don't really need to match the exact same alive range, so // we can just clone into offset 0 regardless of where `self` is. - let mut new = Self { data: MaybeUninit::uninit_array(), alive: IndexRange::zero_to(0) }; + let mut new = + Self { data: MaybeUninit::uninit().transpose(), alive: IndexRange::zero_to(0) }; // Clone all alive elements. for (src, dst) in iter::zip(self.as_slice(), &mut new.data) { diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index b82bbf2267a96..ba7f8357343c7 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -879,7 +879,7 @@ where } } - let mut array = MaybeUninit::uninit_array::(); + let mut array = MaybeUninit::uninit().transpose(); let mut guard = Guard { array_mut: &mut array, initialized: 0 }; for _ in 0..N { diff --git a/library/core/src/fmt/float.rs b/library/core/src/fmt/float.rs index 89d5fac30d357..b06441432e26c 100644 --- a/library/core/src/fmt/float.rs +++ b/library/core/src/fmt/float.rs @@ -35,8 +35,8 @@ fn float_to_decimal_common_exact( where T: flt2dec::DecodableFloat, { - let mut buf: [MaybeUninit; 1024] = MaybeUninit::uninit_array(); // enough for f32 and f64 - let mut parts: [MaybeUninit>; 4] = MaybeUninit::uninit_array(); + let mut buf = [MaybeUninit::::uninit(); 1024]; // enough for f32 and f64 + let mut parts = [MaybeUninit::>::uninit(); 4]; let formatted = flt2dec::to_exact_fixed_str( flt2dec::strategy::grisu::format_exact, *num, @@ -61,8 +61,8 @@ where T: flt2dec::DecodableFloat, { // enough for f32 and f64 - let mut buf: [MaybeUninit; flt2dec::MAX_SIG_DIGITS] = MaybeUninit::uninit_array(); - let mut parts: [MaybeUninit>; 4] = MaybeUninit::uninit_array(); + let mut buf = [MaybeUninit::::uninit(); flt2dec::MAX_SIG_DIGITS]; + let mut parts = [MaybeUninit::>::uninit(); 4]; let formatted = flt2dec::to_shortest_str( flt2dec::strategy::grisu::format_shortest, *num, @@ -105,8 +105,8 @@ fn float_to_exponential_common_exact( where T: flt2dec::DecodableFloat, { - let mut buf: [MaybeUninit; 1024] = MaybeUninit::uninit_array(); // enough for f32 and f64 - let mut parts: [MaybeUninit>; 6] = MaybeUninit::uninit_array(); + let mut buf = [MaybeUninit::::uninit(); 1024]; // enough for f32 and f64 + let mut parts = [MaybeUninit::>::uninit(); 6]; let formatted = flt2dec::to_exact_exp_str( flt2dec::strategy::grisu::format_exact, *num, @@ -132,8 +132,8 @@ where T: flt2dec::DecodableFloat, { // enough for f32 and f64 - let mut buf: [MaybeUninit; flt2dec::MAX_SIG_DIGITS] = MaybeUninit::uninit_array(); - let mut parts: [MaybeUninit>; 6] = MaybeUninit::uninit_array(); + let mut buf = [MaybeUninit::::uninit(); flt2dec::MAX_SIG_DIGITS]; + let mut parts = [MaybeUninit::>::uninit(); 6]; let formatted = flt2dec::to_shortest_exp_str( flt2dec::strategy::grisu::format_shortest, *num, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index da84763836eb4..a2b3fde54befe 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -119,7 +119,6 @@ #![feature(const_int_unchecked_arith)] #![feature(const_intrinsic_forget)] #![feature(const_likely)] -#![feature(const_maybe_uninit_uninit_array)] #![feature(const_maybe_uninit_as_mut_ptr)] #![feature(const_maybe_uninit_assume_init)] #![feature(const_nonnull_new)] @@ -151,7 +150,6 @@ #![feature(const_waker)] #![feature(core_panic)] #![feature(duration_consts_float)] -#![feature(maybe_uninit_uninit_array)] #![feature(ptr_alignment_type)] #![feature(ptr_metadata)] #![feature(slice_ptr_get)] @@ -217,6 +215,7 @@ #![feature(unboxed_closures)] #![feature(unsized_fn_params)] #![feature(asm_const)] +#![feature(const_transmute_copy)] // // Target features: #![feature(arm_target_feature)] diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 2ae9636762813..539a09bff5f09 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -138,7 +138,7 @@ use crate::slice; /// unsafe { mem::transmute::<_, [Vec; 1000]>(data) } /// }; /// -/// assert_eq!(&data[0], &[42]); +/// assert_eq!(&data[42], &[42]); /// ``` /// /// You can also work with partially initialized arrays, which could @@ -148,10 +148,9 @@ use crate::slice; /// use std::mem::MaybeUninit; /// use std::ptr; /// -/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is -/// // safe because the type we are claiming to have initialized here is a -/// // bunch of `MaybeUninit`s, which do not require initialization. -/// let mut data: [MaybeUninit; 1000] = unsafe { MaybeUninit::uninit().assume_init() }; +/// // Create an uninitialized array of `MaybeUninit`. +/// const UNINIT_STRING: MaybeUninit = MaybeUninit::uninit(); +/// let mut data = [UNINIT_STRING; 1000]; /// // Count the number of elements we have assigned. /// let mut data_len: usize = 0; /// @@ -348,6 +347,10 @@ impl MaybeUninit { #[rustc_const_unstable(feature = "const_maybe_uninit_uninit_array", issue = "96097")] #[must_use] #[inline(always)] + #[deprecated( + since = "nightly", + note = "Use const array initialization instead or the transpose methods." + )] pub const fn uninit_array() -> [Self; N] { // SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid. unsafe { MaybeUninit::<[MaybeUninit; N]>::uninit().assume_init() } @@ -1297,7 +1300,8 @@ impl MaybeUninit<[T; N]> { /// let data: [MaybeUninit; 1000] = MaybeUninit::uninit().transpose(); /// ``` #[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")] - pub fn transpose(self) -> [MaybeUninit; N] { + #[inline(always)] + pub const fn transpose(self) -> [MaybeUninit; N] { // SAFETY: T and MaybeUninit have the same layout unsafe { super::transmute_copy(&ManuallyDrop::new(self)) } } @@ -1316,7 +1320,8 @@ impl [MaybeUninit; N] { /// let data: MaybeUninit<[u8; 1000]> = data.transpose(); /// ``` #[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")] - pub fn transpose(self) -> MaybeUninit<[T; N]> { + #[inline(always)] + pub const fn transpose(self) -> MaybeUninit<[T; N]> { // SAFETY: T and MaybeUninit have the same layout unsafe { super::transmute_copy(&ManuallyDrop::new(self)) } } diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index b5c34f5df3b76..6be3faf35d3a2 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -48,7 +48,6 @@ #![feature(slice_take)] #![feature(slice_from_ptr_range)] #![feature(split_as_slice)] -#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_array_assume_init)] #![feature(maybe_uninit_write_slice)] #![feature(min_specialization)] diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 6856d1a1f51ae..9924b01013269 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -163,7 +163,7 @@ fn assume_init_good() { #[test] fn uninit_array_assume_init() { - let mut array: [MaybeUninit; 5] = MaybeUninit::uninit_array(); + let mut array = [MaybeUninit::::uninit(); 5]; array[0].write(3); array[1].write(1); array[2].write(4); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 78838adb8dd27..863d2be2ae060 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -312,8 +312,7 @@ #![feature(std_internals)] #![feature(str_internals)] #![feature(strict_provenance)] -#![feature(maybe_uninit_uninit_array)] -#![feature(const_maybe_uninit_uninit_array)] +#![feature(maybe_uninit_uninit_array_transpose)] #![feature(const_waker)] // // Library features (alloc): diff --git a/library/std/src/net/display_buffer.rs b/library/std/src/net/display_buffer.rs index 7aadf06e92fc6..8b0ede922b3d2 100644 --- a/library/std/src/net/display_buffer.rs +++ b/library/std/src/net/display_buffer.rs @@ -11,7 +11,7 @@ pub struct DisplayBuffer { impl DisplayBuffer { #[inline] pub const fn new() -> Self { - Self { buf: MaybeUninit::uninit_array(), len: 0 } + Self { buf: MaybeUninit::uninit().transpose(), len: 0 } } #[inline] diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index eab9b961279c9..1cbf48e0da4a8 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -205,7 +205,7 @@ where // This initial size also works around `GetFullPathNameW` returning // incorrect size hints for some short paths: // https://github.com/dylni/normpath/issues/5 - let mut stack_buf: [MaybeUninit; 512] = MaybeUninit::uninit_array(); + let mut stack_buf = [MaybeUninit::::uninit(); 512]; let mut heap_buf: Vec> = Vec::new(); unsafe { let mut n = stack_buf.len();