Skip to content

Commit 3e3bbf3

Browse files
committed
Auto merge of #149102 - bend-n:maybe_uninit_slice, r=joboet
stabilize maybe_uninit_slice Tracking issue: #63569 Closes: #63569 FCP completed: #63569 (comment) Removes: ```rs pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T; pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T; ```
2 parents dfe1b8c + d67f99a commit 3e3bbf3

File tree

9 files changed

+12
-34
lines changed

9 files changed

+12
-34
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
// tidy-alphabetical-start
1111
#![allow(clippy::mut_from_ref)] // Arena allocators are one place where this pattern is fine.
1212
#![allow(internal_features)]
13+
#![cfg_attr(bootstrap, feature(maybe_uninit_slice))]
1314
#![cfg_attr(test, feature(test))]
1415
#![deny(unsafe_op_in_unsafe_fn)]
1516
#![doc(test(no_crate_inject, attr(deny(warnings), allow(internal_features))))]
1617
#![feature(core_intrinsics)]
1718
#![feature(decl_macro)]
1819
#![feature(dropck_eyepatch)]
19-
#![feature(maybe_uninit_slice)]
2020
#![feature(never_type)]
2121
#![feature(rustc_attrs)]
2222
#![feature(unwrap_infallible)]

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
#![feature(layout_for_ptr)]
128128
#![feature(legacy_receiver_trait)]
129129
#![feature(local_waker)]
130-
#![feature(maybe_uninit_slice)]
131130
#![feature(maybe_uninit_uninit_array_transpose)]
132131
#![feature(panic_internals)]
133132
#![feature(pattern)]

library/alloctests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(inplace_iteration)]
2929
#![feature(iter_advance_by)]
3030
#![feature(iter_next_chunk)]
31-
#![feature(maybe_uninit_slice)]
3231
#![feature(maybe_uninit_uninit_array_transpose)]
3332
#![feature(ptr_alignment_type)]
3433
#![feature(ptr_internals)]

library/core/src/clone/uninit.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,10 @@ impl<'a, T> InitializingSlice<'a, T> {
114114
impl<'a, T> Drop for InitializingSlice<'a, T> {
115115
#[cold] // will only be invoked on unwind
116116
fn drop(&mut self) {
117-
let initialized_slice = ptr::slice_from_raw_parts_mut(
118-
MaybeUninit::slice_as_mut_ptr(self.data),
119-
self.initialized_len,
120-
);
121117
// SAFETY:
122118
// * the pointer is valid because it was made from a mutable reference
123119
// * `initialized_len` counts the initialized elements as an invariant of this type,
124120
// so each of the pointed-to elements is initialized and may be dropped.
125-
unsafe {
126-
ptr::drop_in_place::<[T]>(initialized_slice);
127-
}
121+
unsafe { self.data[..self.initialized_len].assume_init_drop() };
128122
}
129123
}

library/core/src/mem/maybe_uninit.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ impl<T> MaybeUninit<T> {
10471047
/// # Examples
10481048
///
10491049
/// ```
1050-
/// #![feature(maybe_uninit_as_bytes, maybe_uninit_slice)]
1050+
/// #![feature(maybe_uninit_as_bytes)]
10511051
/// use std::mem::MaybeUninit;
10521052
///
10531053
/// let val = 0x12345678_i32;
@@ -1097,20 +1097,6 @@ impl<T> MaybeUninit<T> {
10971097
)
10981098
}
10991099
}
1100-
1101-
/// Gets a pointer to the first element of the array.
1102-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1103-
#[inline(always)]
1104-
pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T {
1105-
this.as_ptr() as *const T
1106-
}
1107-
1108-
/// Gets a mutable pointer to the first element of the array.
1109-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1110-
#[inline(always)]
1111-
pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T {
1112-
this.as_mut_ptr() as *mut T
1113-
}
11141100
}
11151101

11161102
impl<T> [MaybeUninit<T>] {
@@ -1410,7 +1396,7 @@ impl<T> [MaybeUninit<T>] {
14101396
/// # Examples
14111397
///
14121398
/// ```
1413-
/// #![feature(maybe_uninit_as_bytes, maybe_uninit_slice)]
1399+
/// #![feature(maybe_uninit_as_bytes)]
14141400
/// use std::mem::MaybeUninit;
14151401
///
14161402
/// let uninit = [MaybeUninit::new(0x1234u16), MaybeUninit::new(0x5678u16)];
@@ -1437,7 +1423,7 @@ impl<T> [MaybeUninit<T>] {
14371423
/// # Examples
14381424
///
14391425
/// ```
1440-
/// #![feature(maybe_uninit_as_bytes, maybe_uninit_slice)]
1426+
/// #![feature(maybe_uninit_as_bytes)]
14411427
/// use std::mem::MaybeUninit;
14421428
///
14431429
/// let mut uninit = [MaybeUninit::<u16>::uninit(), MaybeUninit::<u16>::uninit()];
@@ -1477,7 +1463,7 @@ impl<T> [MaybeUninit<T>] {
14771463
/// requirement the compiler knows about it is that the data pointer must be
14781464
/// non-null. Dropping such a `Vec<T>` however will cause undefined
14791465
/// behaviour.
1480-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1466+
#[stable(feature = "maybe_uninit_slice", since = "CURRENT_RUSTC_VERSION")]
14811467
#[inline(always)]
14821468
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
14831469
pub const unsafe fn assume_init_drop(&mut self)
@@ -1499,7 +1485,8 @@ impl<T> [MaybeUninit<T>] {
14991485
/// Calling this when the content is not yet fully initialized causes undefined
15001486
/// behavior: it is up to the caller to guarantee that every `MaybeUninit<T>` in
15011487
/// the slice really is in an initialized state.
1502-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1488+
#[stable(feature = "maybe_uninit_slice", since = "CURRENT_RUSTC_VERSION")]
1489+
#[rustc_const_stable(feature = "maybe_uninit_slice", since = "CURRENT_RUSTC_VERSION")]
15031490
#[inline(always)]
15041491
pub const unsafe fn assume_init_ref(&self) -> &[T] {
15051492
// SAFETY: casting `slice` to a `*const [T]` is safe since the caller guarantees that
@@ -1517,7 +1504,8 @@ impl<T> [MaybeUninit<T>] {
15171504
/// behavior: it is up to the caller to guarantee that every `MaybeUninit<T>` in the
15181505
/// slice really is in an initialized state. For instance, `.assume_init_mut()` cannot
15191506
/// be used to initialize a `MaybeUninit` slice.
1520-
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1507+
#[stable(feature = "maybe_uninit_slice", since = "CURRENT_RUSTC_VERSION")]
1508+
#[rustc_const_stable(feature = "maybe_uninit_slice", since = "CURRENT_RUSTC_VERSION")]
15211509
#[inline(always)]
15221510
pub const unsafe fn assume_init_mut(&mut self) -> &mut [T] {
15231511
// SAFETY: similar to safety notes for `slice_get_ref`, but we have a

library/core/src/slice/sort/stable/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn merge<T, F: FnMut(&T, &T) -> bool>(
3535
// 1. Protects integrity of `v` from panics in `is_less`.
3636
// 2. Fills the remaining gap in `v` if the longer run gets consumed first.
3737

38-
let buf = MaybeUninit::slice_as_mut_ptr(scratch);
38+
let buf = scratch.as_mut_ptr().cast_init();
3939

4040
let v_base = v.as_mut_ptr();
4141
let v_mid = v_base.add(mid);

library/core/src/slice/sort/stable/quicksort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn stable_partition<T, F: FnMut(&T, &T) -> bool>(
9797
}
9898

9999
let v_base = v.as_ptr();
100-
let scratch_base = MaybeUninit::slice_as_mut_ptr(scratch);
100+
let scratch_base = scratch.as_mut_ptr().cast_init();
101101

102102
// The core idea is to write the values that compare as less-than to the left
103103
// side of `scratch`, while the values that compared as greater or equal than

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@
346346
#![feature(ip)]
347347
#![feature(lazy_get)]
348348
#![feature(maybe_uninit_array_assume_init)]
349-
#![feature(maybe_uninit_slice)]
350349
#![feature(panic_can_unwind)]
351350
#![feature(panic_internals)]
352351
#![feature(pin_coerce_unsized_trait)]

library/std/tests/path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tidy-alphabetical-start
22
#![feature(clone_to_uninit)]
3-
#![feature(maybe_uninit_slice)]
43
#![feature(normalize_lexically)]
54
#![feature(path_trailing_sep)]
65
// tidy-alphabetical-end

0 commit comments

Comments
 (0)