Skip to content

Commit

Permalink
Rollup merge of rust-lang#129401 - workingjubilee:partial-initializat…
Browse files Browse the repository at this point in the history
…ion-of-stabilization, r=dtolnay,joboet

Partially stabilize `feature(new_uninit)`

Finished comment period: rust-lang#63291 (comment)

The following API has been stabilized from rust-lang#63291

```rust
impl<T> Box<T> { pub fn new_uninit() -> Box<MaybeUninit<T>> {…} }
impl<T> Rc<T> { pub fn new_uninit() -> Rc<MaybeUninit<T>> {…} }
impl<T> Arc<T> { pub fn new_uninit() -> Arc<MaybeUninit<T>> {…} }

impl<T> Box<[T]> { pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]> {…} }
impl<T> Rc<[T]> { pub fn new_uninit_slice(len: usize) -> Rc<[MaybeUninit<T>]> {…} }
impl<T> Arc<[T]> { pub fn new_uninit_slice(len: usize) -> Arc<[MaybeUninit<T>]> {…} }

impl<T> Box<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Box<T> {…} }
impl<T> Box<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Box<[T]> {…} }
impl<T> Rc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Rc<T> {…} }
impl<T> Rc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Rc<[T]> {…} }
impl<T> Arc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Arc<T> {…} }
impl<T> Arc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Arc<[T]> {…} }
```

The remaining API is split between new issues
- `new_zeroed_alloc`: rust-lang#129396
- `box_uninit_write`: rust-lang#129397

All relevant code is thus either stabilized or split out of that issue, so this closes rust-lang#63291 as, with the FCP concluded, that issue has served its purpose.

try-job: x86_64-rust-for-linux
  • Loading branch information
workingjubilee authored Aug 29, 2024
2 parents fcb6b77 + 605d9cf commit 9d5f794
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 76 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#![feature(decl_macro)]
#![feature(dropck_eyepatch)]
#![feature(maybe_uninit_slice)]
#![feature(new_uninit)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![feature(strict_provenance)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tidy-alphabetical-start
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
#![cfg_attr(feature = "nightly", allow(internal_features))]
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
#![cfg_attr(feature = "nightly", feature(extend_one, step_trait, test))]
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(new_uninit)]
#![feature(ptr_alignment_type)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(new_uninit)]
#![feature(read_buf)]
#![feature(round_char_boundary)]
#![feature(rustc_attrs)]
Expand Down
43 changes: 16 additions & 27 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ impl<T> Box<T> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let mut five = Box::<u32>::new_uninit();
///
/// let five = unsafe {
Expand All @@ -276,7 +274,7 @@ impl<T> Box<T> {
/// assert_eq!(*five, 5)
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
Expand All @@ -292,7 +290,6 @@ impl<T> Box<T> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(new_zeroed_alloc)]
///
/// let zero = Box::<u32>::new_zeroed();
Expand Down Expand Up @@ -350,7 +347,7 @@ impl<T> Box<T> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// let mut five = Box::<u32>::try_new_uninit()?;
///
Expand Down Expand Up @@ -380,7 +377,7 @@ impl<T> Box<T> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// let zero = Box::<u32>::try_new_zeroed()?;
/// let zero = unsafe { zero.assume_init() };
Expand Down Expand Up @@ -460,7 +457,7 @@ impl<T, A: Allocator> Box<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -498,7 +495,7 @@ impl<T, A: Allocator> Box<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -538,7 +535,7 @@ impl<T, A: Allocator> Box<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -576,7 +573,7 @@ impl<T, A: Allocator> Box<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -654,8 +651,6 @@ impl<T> Box<[T]> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
///
/// let values = unsafe {
Expand All @@ -670,7 +665,7 @@ impl<T> Box<[T]> {
/// assert_eq!(*values, [1, 2, 3])
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
unsafe { RawVec::with_capacity(len).into_box(len) }
Expand All @@ -686,7 +681,6 @@ impl<T> Box<[T]> {
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// let values = Box::<[u32]>::new_zeroed_slice(3);
/// let values = unsafe { values.assume_init() };
Expand All @@ -708,7 +702,7 @@ impl<T> Box<[T]> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// let mut values = Box::<[u32]>::try_new_uninit_slice(3)?;
/// let values = unsafe {
Expand Down Expand Up @@ -746,7 +740,7 @@ impl<T> Box<[T]> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// let values = Box::<[u32]>::try_new_zeroed_slice(3)?;
/// let values = unsafe { values.assume_init() };
Expand Down Expand Up @@ -778,7 +772,7 @@ impl<T, A: Allocator> Box<[T], A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -812,7 +806,7 @@ impl<T, A: Allocator> Box<[T], A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand All @@ -837,7 +831,7 @@ impl<T, A: Allocator> Box<[T], A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -880,7 +874,7 @@ impl<T, A: Allocator> Box<[T], A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand Down Expand Up @@ -927,8 +921,6 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let mut five = Box::<u32>::new_uninit();
///
/// let five: Box<u32> = unsafe {
Expand All @@ -940,7 +932,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
///
/// assert_eq!(*five, 5)
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub unsafe fn assume_init(self) -> Box<T, A> {
let (raw, alloc) = Box::into_raw_with_allocator(self);
Expand All @@ -958,7 +950,6 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
///
/// ```
/// #![feature(box_uninit_write)]
/// #![feature(new_uninit)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
///
Expand Down Expand Up @@ -1001,8 +992,6 @@ impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
///
/// let mut values = Box::<[u32]>::new_uninit_slice(3);
///
/// let values = unsafe {
Expand All @@ -1016,7 +1005,7 @@ impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> {
///
/// assert_eq!(*values, [1, 2, 3])
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub unsafe fn assume_init(self) -> Box<[T], A> {
let (raw, alloc) = Box::into_raw_with_allocator(self);
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
// tidy-alphabetical-start
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
#![cfg_attr(test, feature(new_uninit))]
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(array_chunks)]
Expand Down
26 changes: 8 additions & 18 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand All @@ -518,7 +517,7 @@ impl<T> Rc<T> {
/// assert_eq!(*five, 5)
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> {
unsafe {
Expand All @@ -540,7 +539,6 @@ impl<T> Rc<T> {
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// use std::rc::Rc;
///
Expand Down Expand Up @@ -594,7 +592,7 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand Down Expand Up @@ -630,7 +628,7 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::rc::Rc;
///
Expand Down Expand Up @@ -692,7 +690,6 @@ impl<T, A: Allocator> Rc<T, A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
/// #![feature(allocator_api)]
///
Expand Down Expand Up @@ -736,7 +733,6 @@ impl<T, A: Allocator> Rc<T, A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::rc::Rc;
Expand Down Expand Up @@ -799,7 +795,7 @@ impl<T, A: Allocator> Rc<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand Down Expand Up @@ -843,7 +839,7 @@ impl<T, A: Allocator> Rc<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::rc::Rc;
/// use std::alloc::System;
Expand Down Expand Up @@ -967,7 +963,6 @@ impl<T> Rc<[T]> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand All @@ -985,7 +980,7 @@ impl<T> Rc<[T]> {
/// assert_eq!(*values, [1, 2, 3])
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
unsafe { Rc::from_ptr(Rc::allocate_for_slice(len)) }
Expand All @@ -1000,7 +995,6 @@ impl<T> Rc<[T]> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(new_zeroed_alloc)]
///
/// use std::rc::Rc;
Expand Down Expand Up @@ -1035,7 +1029,6 @@ impl<T, A: Allocator> Rc<[T], A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
/// #![feature(allocator_api)]
///
Expand Down Expand Up @@ -1072,7 +1065,6 @@ impl<T, A: Allocator> Rc<[T], A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(allocator_api)]
///
/// use std::rc::Rc;
Expand Down Expand Up @@ -1122,7 +1114,6 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand All @@ -1136,7 +1127,7 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
///
/// assert_eq!(*five, 5)
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<T, A> {
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
Expand All @@ -1160,7 +1151,6 @@ impl<T, A: Allocator> Rc<[mem::MaybeUninit<T>], A> {
/// # Examples
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(get_mut_unchecked)]
///
/// use std::rc::Rc;
Expand All @@ -1177,7 +1167,7 @@ impl<T, A: Allocator> Rc<[mem::MaybeUninit<T>], A> {
///
/// assert_eq!(*values, [1, 2, 3])
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[stable(feature = "new_uninit", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<[T], A> {
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
Expand Down
Loading

0 comments on commit 9d5f794

Please sign in to comment.