From 3583cf07c8000475053bb06135eadb7866ff6b45 Mon Sep 17 00:00:00 2001 From: Nia Deckers Date: Sun, 31 May 2026 13:54:11 +0200 Subject: [PATCH 1/2] allocator: refactor for stabilisation f my gay ass puppy life --- library/alloc/src/alloc.rs | 6 ++ library/alloc/src/boxed.rs | 34 +++++-- library/alloc/src/boxed/convert.rs | 4 +- library/alloc/src/rc.rs | 24 ++--- library/alloc/src/str.rs | 9 ++ library/alloc/src/sync.rs | 26 +++--- library/core/src/alloc/mod.rs | 91 ++++++++++++++----- library/std/src/alloc.rs | 6 ++ tests/ui/allocator/dyn-compatible.rs | 13 --- tests/ui/allocator/dyn-incompatible.rs | 13 +++ tests/ui/allocator/dyn-incompatible.stderr | 27 ++++++ tests/ui/lexer/crlf-in-byte-string-literal.rs | 4 +- 12 files changed, 185 insertions(+), 72 deletions(-) delete mode 100644 tests/ui/allocator/dyn-compatible.rs create mode 100644 tests/ui/allocator/dyn-incompatible.rs create mode 100644 tests/ui/allocator/dyn-incompatible.stderr diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index e2dc87061348e..9e7a13922e9e2 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -57,6 +57,12 @@ unsafe extern "Rust" { #[lang = "global_alloc_ty"] pub struct Global; +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl core::alloc::AllocatorClone for Global {} + +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl core::alloc::PinSafeAllocator for Global {} + /// Allocates memory with the global allocator. /// /// This function forwards calls to the [`GlobalAlloc::alloc`] method diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index bd3f10a16dd9b..40a8582e22bb1 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -206,10 +206,12 @@ use core::task::{Context, Poll}; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; -use crate::alloc::{AllocError, Allocator, Global, Layout}; +use crate::alloc::{ + AllocError, Allocator, AllocatorClone, AllocatorEq, Global, Layout, PinSafeAllocator, +}; use crate::raw_vec::RawVec; #[cfg(not(no_global_oom_handling))] -use crate::str::from_boxed_utf8_unchecked; +use crate::str::from_boxed_utf8_unchecked_in; /// Conversion related impls for `Box<_>` (`From`, `downcast`, etc) mod convert; @@ -710,7 +712,7 @@ impl Box { #[inline(always)] pub fn pin_in(x: T, alloc: A) -> Pin where - A: 'static + Allocator, + A: PinSafeAllocator, { Self::into_pin(Self::new_in(x, alloc)) } @@ -1935,7 +1937,7 @@ impl Box { #[stable(feature = "box_into_pin", since = "1.63.0")] pub fn into_pin(boxed: Self) -> Pin where - A: 'static, + A: PinSafeAllocator, { // It's not possible to move or replace the insides of a `Pin>` // when `T: !Unpin`, so it's safe to pin it directly without any @@ -2109,11 +2111,10 @@ impl Clone for Box<[T], A> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_slice_clone", since = "1.3.0")] -impl Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { - // this makes a copy of the data - let buf: Box<[u8]> = self.as_bytes().into(); - unsafe { from_boxed_utf8_unchecked(buf) } + let buf = Box::clone_from_ref_in(self.as_bytes(), self.1.clone()); + unsafe { from_boxed_utf8_unchecked_in(buf) } } } @@ -2485,3 +2486,20 @@ unsafe impl Allocator for Box { unsafe { (**self).shrink(ptr, old_layout, new_layout) } } } + +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl AllocatorClone for Box +where + T: AllocatorClone, + A: Allocator, + Box: Clone, +{ +} + +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl AllocatorEq for Box +where + T: AllocatorEq + ?Sized, + A: Allocator, +{ +} diff --git a/library/alloc/src/boxed/convert.rs b/library/alloc/src/boxed/convert.rs index d6a8e78991b84..81c19e81146bd 100644 --- a/library/alloc/src/boxed/convert.rs +++ b/library/alloc/src/boxed/convert.rs @@ -5,7 +5,7 @@ use core::fmt; use core::mem; use core::pin::Pin; -use crate::alloc::Allocator; +use crate::alloc::{Allocator, PinSafeAllocator}; #[cfg(not(no_global_oom_handling))] use crate::borrow::Cow; use crate::boxed::Box; @@ -38,7 +38,7 @@ impl From for Box { #[stable(feature = "pin", since = "1.33.0")] impl From> for Pin> where - A: 'static, + A: PinSafeAllocator, { /// Converts a `Box` into a `Pin>`. If `T` does not implement [`Unpin`], then /// `*boxed` will be pinned in memory and unable to be moved. diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 523c9b8b15858..a79f1d8992caf 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -268,7 +268,7 @@ use core::{borrow, fmt, hint}; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; -use crate::alloc::{AllocError, Allocator, Global, Layout}; +use crate::alloc::{AllocError, Allocator, AllocatorClone, Global, Layout}; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; #[cfg(not(no_global_oom_handling))] @@ -1773,7 +1773,7 @@ impl Rc { #[stable(feature = "rc_weak", since = "1.4.0")] pub fn downgrade(this: &Self) -> Weak where - A: Clone, + A: AllocatorClone, { this.inner().inc_weak(); // Make sure we do not create a dangling Weak @@ -1854,7 +1854,7 @@ impl Rc { #[unstable(feature = "allocator_api", issue = "32838")] pub unsafe fn increment_strong_count_in(ptr: *const T, alloc: A) where - A: Clone, + A: AllocatorClone, { // Retain Rc, but don't touch refcount by wrapping in ManuallyDrop let rc = unsafe { mem::ManuallyDrop::new(Rc::::from_raw_in(ptr, alloc)) }; @@ -2030,7 +2030,7 @@ impl Rc { } #[cfg(not(no_global_oom_handling))] -impl Rc { +impl Rc { /// Makes a mutable reference into the given `Rc`. /// /// If there are other `Rc` pointers to the same allocation, then `make_mut` will @@ -2305,7 +2305,7 @@ impl Rc { // Free the allocation without dropping its contents let (bptr, alloc) = Box::into_raw_with_allocator(src); - let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop, alloc.by_ref()); + let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop, &alloc); drop(src); Self::from_ptr_in(ptr, alloc) @@ -2494,7 +2494,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc { } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Rc { +impl Clone for Rc { /// Makes a clone of the `Rc` pointer. /// /// This creates another pointer to the same allocation, increasing the @@ -2519,10 +2519,10 @@ impl Clone for Rc { } #[unstable(feature = "ergonomic_clones", issue = "132290")] -impl UseCloned for Rc {} +impl UseCloned for Rc {} #[unstable(feature = "share_trait", issue = "156756")] -impl Share for Rc {} +impl Share for Rc {} #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] @@ -3543,7 +3543,7 @@ impl Weak { #[stable(feature = "rc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> where - A: Clone, + A: AllocatorClone, { let inner = self.inner()?; @@ -3688,7 +3688,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Weak { } #[stable(feature = "rc_weak", since = "1.4.0")] -impl Clone for Weak { +impl Clone for Weak { /// Makes a clone of the `Weak` pointer that points to the same allocation. /// /// # Examples @@ -3710,7 +3710,7 @@ impl Clone for Weak { } #[unstable(feature = "ergonomic_clones", issue = "132290")] -impl UseCloned for Weak {} +impl UseCloned for Weak {} #[stable(feature = "rc_weak", since = "1.4.0")] impl fmt::Debug for Weak { @@ -4410,7 +4410,7 @@ impl UniqueRc { } } -impl UniqueRc { +impl UniqueRc { /// Creates a new weak reference to the `UniqueRc`. /// /// Attempting to upgrade this weak reference will fail before the `UniqueRc` has been converted diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index cf04402e3d984..064790bbf16e4 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -794,6 +794,15 @@ pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box { unsafe { Box::from_raw(Box::into_raw(v) as *mut str) } } +#[doc(hidden)] +#[unstable(feature = "allocator_api", issue = "32838")] +pub unsafe fn from_boxed_utf8_unchecked_in( + v: Box<[u8], A>, +) -> Box { + let (ptr, alloc) = Box::into_raw_with_allocator(v); + unsafe { Box::from_raw_in(ptr as *mut str, alloc) } +} + /// Converts leading ascii bytes in `s` by calling the `convert` function. /// /// For better average performance, this happens in chunks of `2*size_of::()`. diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 4a9878d8e249d..8c717a7b2e242 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -35,7 +35,7 @@ use core::{borrow, fmt, hint}; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; -use crate::alloc::{AllocError, Allocator, Global, Layout}; +use crate::alloc::{AllocError, Allocator, AllocatorClone, Global, Layout}; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; use crate::rc::is_dangling; @@ -1931,7 +1931,7 @@ impl Arc { #[stable(feature = "arc_weak", since = "1.4.0")] pub fn downgrade(this: &Self) -> Weak where - A: Clone, + A: AllocatorClone, { // This Relaxed is OK because we're checking the value in the CAS // below. @@ -2062,7 +2062,7 @@ impl Arc { #[unstable(feature = "allocator_api", issue = "32838")] pub unsafe fn increment_strong_count_in(ptr: *const T, alloc: A) where - A: Clone, + A: AllocatorClone, { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop let arc = unsafe { mem::ManuallyDrop::new(Arc::from_raw_in(ptr, alloc)) }; @@ -2250,7 +2250,7 @@ impl Arc { // Free the allocation without dropping its contents let (bptr, alloc) = Box::into_raw_with_allocator(src); - let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop, alloc.by_ref()); + let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop, &alloc); drop(src); Self::from_ptr_in(ptr, alloc) @@ -2376,7 +2376,7 @@ impl ArcFromSlice for Arc<[T]> { } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Arc { +impl Clone for Arc { /// Makes a clone of the `Arc` pointer. /// /// This creates another pointer to the same allocation, increasing the @@ -2430,10 +2430,10 @@ impl Clone for Arc { } #[unstable(feature = "ergonomic_clones", issue = "132290")] -impl UseCloned for Arc {} +impl UseCloned for Arc {} #[unstable(feature = "share_trait", issue = "156756")] -impl Share for Arc {} +impl Share for Arc {} #[stable(feature = "rust1", since = "1.0.0")] impl Deref for Arc { @@ -2455,7 +2455,7 @@ unsafe impl DerefPure for Arc {} impl LegacyReceiver for Arc {} #[cfg(not(no_global_oom_handling))] -impl Arc { +impl Arc { /// Makes a mutable reference into the given `Arc`. /// /// If there are other `Arc` pointers to the same allocation, then `make_mut` will @@ -3274,7 +3274,7 @@ impl Weak { #[stable(feature = "arc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> where - A: Clone, + A: AllocatorClone, { #[inline] fn checked_increment(n: usize) -> Option { @@ -3409,7 +3409,7 @@ impl Weak { } #[stable(feature = "arc_weak", since = "1.4.0")] -impl Clone for Weak { +impl Clone for Weak { /// Makes a clone of the `Weak` pointer that points to the same allocation. /// /// # Examples @@ -3441,7 +3441,7 @@ impl Clone for Weak { } #[unstable(feature = "ergonomic_clones", issue = "132290")] -impl UseCloned for Weak {} +impl UseCloned for Weak {} #[stable(feature = "downgraded_weak", since = "1.10.0")] impl Default for Weak { @@ -4029,7 +4029,7 @@ impl From> for Arc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Arc<[T], A> { +impl From> for Arc<[T], A> { /// Allocates a reference-counted slice and moves `v`'s items into it. /// /// # Example @@ -4839,7 +4839,7 @@ impl UniqueArc { } } -impl UniqueArc { +impl UniqueArc { /// Creates a new weak reference to the `UniqueArc`. /// /// Attempting to upgrade this weak reference will fail before the `UniqueArc` has been converted diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 18310cf98918d..eabe7f2e9f24a 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -82,7 +82,8 @@ impl fmt::Display for AllocError { /// * the memory block must be *currently allocated* with alignment of [`layout.align()`], and /// * [`layout.size()`] must fall in the range `min ..= max`, where: /// - `min` is the size of the layout used to allocate the block, and -/// - `max` is the actual size returned from [`allocate`], [`grow`], or [`shrink`]. +/// - `max` is the actual size returned from [`allocate`], [`grow`], [`shrink`], +/// or their respective zeroed variants. /// /// [`layout.align()`]: Layout::align /// [`layout.size()`]: Layout::size @@ -90,9 +91,14 @@ impl fmt::Display for AllocError { /// # Safety /// /// Memory blocks that are [*currently allocated*] by an allocator, -/// must point to valid memory, and retain their validity until either: -/// - the memory block is deallocated, or -/// - the allocator is dropped. +/// must point to memory which is valid for both reads and writes where the +/// blocks do not overlap, and they must retain their validity until either: +/// - the memory block is deallocated, +/// - the allocator is mutated through public API taking `&mut` access (notably, +/// running the allocator's destructor is such a mutation), or +/// - the allocator's type becomes invalid. +/// (For example, the type `&'a T` becomes invalid when `'a` expires. +/// More generally, a type becomes invalid when any of its lifetime parameters has expired.) /// /// Copying, cloning, or moving the allocator must not invalidate memory blocks returned from it. /// A copied or cloned allocator must behave like the original allocator. @@ -100,6 +106,10 @@ impl fmt::Display for AllocError { /// A memory block which is [*currently allocated*] may be passed to /// any method of the allocator that accepts such an argument. /// +/// Users of this trait must not rely on side effects of allocating or deallocating method calls +/// on `Allocator` implementors being observable (i.e. it is sound for an allocation followed +/// immediately by a deallocation to be optimised away). +/// /// Additionally, any memory block returned by the allocator must /// satisfy the allocation invariants described in `core::ptr`. /// In particular, if a block has base address `p` and size `n`, @@ -107,9 +117,24 @@ impl fmt::Display for AllocError { /// /// This ensures that pointer arithmetic within the allocation /// (for example, `ptr.add(len)`) cannot overflow the address space. +/// +/// Additionally, the following requirements must be upheld by implementors, but are still +/// considered experimental and thus downstream users cannot rely on them being upheld for +/// correctness as they may be relaxed in the future: +/// +/// The pointer passed back in via de/reallocating methods must only be used to access +/// memory inside of that allocation. Furthermore, this pointer should be considered +/// "mutably borrowed" from the pointer returned by (re)allocating methods and the usual +/// aliasing rules for mutable borrows apply: when their lifetime ends (e.g. because a +/// pointer they were derived from gets used again), they are invalidated must not be used +/// anymore. +/// +/// Implementors of the trait must guarantee that none of the methods on this trait unwind. +/// /// [*currently allocated*]: #currently-allocated-memory #[unstable(feature = "allocator_api", issue = "32838")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] +#[rustc_dyn_incompatible_trait] pub const unsafe trait Allocator { /// Attempts to allocate a block of memory. /// @@ -118,9 +143,9 @@ pub const unsafe trait Allocator { /// The returned block may have a larger size than specified by `layout.size()`, and may or may /// not have its contents initialized. /// - /// The returned block of memory remains valid as long as it is [*currently allocated*] and the shorter of: - /// - the borrow-checker lifetime of the allocator type itself. - /// - as long as the allocator and all its clones have not been dropped. + /// The returned block of memory remains valid as long as it is [*currently allocated*] and + /// the borrow-checker lifetime of the allocator type has not expired. Note that implementors + /// which are also [`AllocatorClone`] must obey stricter semantics. /// /// [*currently allocated*]: #currently-allocated-memory /// @@ -129,7 +154,7 @@ pub const unsafe trait Allocator { /// Returning `Err` indicates that either memory is exhausted or `layout` does not meet /// allocator's size or alignment constraints. /// - /// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or + /// Implementations are encouraged to return `Err` on memory exhaustion rather than /// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement /// this trait atop an underlying native allocation library that aborts on memory exhaustion.) /// @@ -146,7 +171,7 @@ pub const unsafe trait Allocator { /// Returning `Err` indicates that either memory is exhausted or `layout` does not meet /// allocator's size or alignment constraints. /// - /// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or + /// Implementations are encouraged to return `Err` on memory exhaustion rather than /// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement /// this trait atop an underlying native allocation library that aborts on memory exhaustion.) /// @@ -168,6 +193,11 @@ pub const unsafe trait Allocator { /// * `ptr` must denote a block of memory [*currently allocated*] via this allocator, and /// * `layout` must [*fit*] that block of memory. /// + /// Note that it is UB for a deallocation or reallocation to invalidate any + /// outstanding references, `Rc<_>`s, etc.; thus, notably, an allocator that has + /// been moved into its own [*currently allocated*] memory must not be invalidated + /// by a call to this method, as it would invalidate the `&self` reference used. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); @@ -202,7 +232,7 @@ pub const unsafe trait Allocator { /// Returns `Err` if the new layout does not meet the allocator's size and alignment /// constraints of the allocator, or if growing otherwise fails. /// - /// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or + /// Implementations are encouraged to return `Err` on memory exhaustion rather than /// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement /// this trait atop an underlying native allocation library that aborts on memory exhaustion.) /// @@ -265,7 +295,7 @@ pub const unsafe trait Allocator { /// Returns `Err` if the new layout does not meet the allocator's size and alignment /// constraints of the allocator, or if growing otherwise fails. /// - /// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or + /// Implementations are encouraged to return `Err` on memory exhaustion rather than /// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement /// this trait atop an underlying native allocation library that aborts on memory exhaustion.) /// @@ -329,7 +359,7 @@ pub const unsafe trait Allocator { /// Returns `Err` if the new layout does not meet the allocator's size and alignment /// constraints of the allocator, or if shrinking otherwise fails. /// - /// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or + /// Implementations are encouraged to return `Err` on memory exhaustion rather than /// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement /// this trait atop an underlying native allocation library that aborts on memory exhaustion.) /// @@ -362,19 +392,36 @@ pub const unsafe trait Allocator { Ok(new_ptr) } +} - /// Creates a "by reference" adapter for this instance of `Allocator`. - /// - /// The returned adapter also implements `Allocator` and will simply borrow this. - #[inline(always)] - fn by_ref(&self) -> &Self - where - Self: Sized, - { - self - } +/// Marks a type's [`Clone`] implementation as sound with regard to [`Allocator`]. +/// Implementors must ensure that, upon cloning, the two allocators are interchangeable +/// (i.e. is is possible to free memory with one that was allocated with the other). +/// Further, mutable accesses such as moving or dropping the allocator must not invalidate +/// its currently allocated blocks at least so long as clones exist. +#[unstable(feature = "allocator_api", issue = "32838")] +pub unsafe trait AllocatorClone: Allocator + Clone {} + +/// Marks a type's [`PartialEq`] implementation as sound with regard to [`Allocator`]. +/// Implementors must ensure that, upon equality, the two allocators are interchangeable +/// (i.e. is is possible to free memory with one that was allocated with the other), and +/// that the two allocators behave "as if" they are clones of each other as per +/// [`AllocatorClone`]. +#[unstable(feature = "allocator_api", issue = "32838")] +pub unsafe trait AllocatorEq: Allocator + PartialEq +where + T: ?Sized + AllocatorEq, +{ } +/// Marks that an allocator will not break [`Pin`] guarantees, even if subtyped with a +/// shorter lifetime. This trivially applies to allocators that always maintain +/// global state, e.g. `System` or `Global`. +/// +/// [`Pin`]: ../../core/pin/struct.Pin.html +#[unstable(feature = "allocator_api", issue = "32838")] +pub unsafe trait PinSafeAllocator: Allocator + 'static {} + #[unstable(feature = "allocator_api", issue = "32838")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] unsafe impl const Allocator for &A diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 7a576e083df7c..f44008c791468 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -138,6 +138,12 @@ pub use alloc_crate::alloc::*; #[derive(Debug, Default, Copy, Clone)] pub struct System; +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl core::alloc::AllocatorClone for System {} + +#[unstable(feature = "allocator_api", issue = "32838")] +unsafe impl core::alloc::PinSafeAllocator for System {} + impl System { #[inline] fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result, AllocError> { diff --git a/tests/ui/allocator/dyn-compatible.rs b/tests/ui/allocator/dyn-compatible.rs deleted file mode 100644 index 9d8235e58d929..0000000000000 --- a/tests/ui/allocator/dyn-compatible.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass - -// Check that `Allocator` is dyn-compatible, this allows for polymorphic allocators - -#![feature(allocator_api)] - -use std::alloc::{Allocator, System}; - -fn ensure_dyn_compatible(_: &dyn Allocator) {} - -fn main() { - ensure_dyn_compatible(&System); -} diff --git a/tests/ui/allocator/dyn-incompatible.rs b/tests/ui/allocator/dyn-incompatible.rs new file mode 100644 index 0000000000000..3e4c12fd1c73d --- /dev/null +++ b/tests/ui/allocator/dyn-incompatible.rs @@ -0,0 +1,13 @@ +// Check that `Allocator` is dyn-incompatible, to keep the design space open. + +#![feature(allocator_api)] + +use std::alloc::{Allocator, System}; + +fn ensure_dyn_incompatible(_: &dyn Allocator) {} +//~^ ERROR E0038 + +fn main() { + ensure_dyn_incompatible(&System); + //~^ ERROR E0038 +} diff --git a/tests/ui/allocator/dyn-incompatible.stderr b/tests/ui/allocator/dyn-incompatible.stderr new file mode 100644 index 0000000000000..8f6dbf4f5ec79 --- /dev/null +++ b/tests/ui/allocator/dyn-incompatible.stderr @@ -0,0 +1,27 @@ +error[E0038]: the trait `Allocator` is not dyn compatible + --> $DIR/dyn-incompatible.rs:7:32 + | +LL | fn ensure_dyn_incompatible(_: &dyn Allocator) {} + | ^^^^^^^^^^^^^ `Allocator` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/alloc/mod.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error[E0038]: the trait `Allocator` is not dyn compatible + --> $DIR/dyn-incompatible.rs:11:29 + | +LL | ensure_dyn_incompatible(&System); + | ^^^^^^^ `Allocator` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $SRC_DIR/core/src/alloc/mod.rs:LL:COL + | + = note: the trait is not dyn compatible because it opted out of dyn-compatibility + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/lexer/crlf-in-byte-string-literal.rs b/tests/ui/lexer/crlf-in-byte-string-literal.rs index 1290133d7014e..9d348d6eafd56 100644 --- a/tests/ui/lexer/crlf-in-byte-string-literal.rs +++ b/tests/ui/lexer/crlf-in-byte-string-literal.rs @@ -5,8 +5,8 @@ // this file has some special \r\n endings (use xxd to see them) -fn main() {assert_eq!(b"", b"\ +fn main() {assert_eq!(b"", b"\ "); -assert_eq!(b"\n", b" +assert_eq!(b"\n", b" "); } From f038322fb74d70e2e931942ec402ced80787fca6 Mon Sep 17 00:00:00 2001 From: Nia Deckers Date: Sun, 31 May 2026 13:56:23 +0200 Subject: [PATCH 2/2] alloc: stabilise `Allocator` --- compiler/rustc_data_structures/src/lib.rs | 3 +- compiler/rustc_middle/src/lib.rs | 3 +- library/alloc/src/alloc.rs | 8 +- library/alloc/src/boxed.rs | 111 +++++++++--------- library/alloc/src/boxed/thin.rs | 1 - .../alloc/src/collections/binary_heap/mod.rs | 33 +++--- library/alloc/src/collections/btree/map.rs | 15 ++- .../alloc/src/collections/btree/map/entry.rs | 8 +- library/alloc/src/collections/btree/set.rs | 20 ++-- .../alloc/src/collections/btree/set/entry.rs | 6 +- library/alloc/src/collections/linked_list.rs | 14 +-- .../alloc/src/collections/vec_deque/drain.rs | 2 +- .../src/collections/vec_deque/extract_if.rs | 4 +- .../src/collections/vec_deque/into_iter.rs | 2 +- .../alloc/src/collections/vec_deque/mod.rs | 12 +- .../alloc/src/collections/vec_deque/splice.rs | 2 +- library/alloc/src/lib.rs | 2 +- library/alloc/src/rc.rs | 101 ++++++++-------- library/alloc/src/slice.rs | 4 +- library/alloc/src/str.rs | 2 +- library/alloc/src/sync.rs | 109 +++++++++-------- library/alloc/src/vec/drain.rs | 4 +- library/alloc/src/vec/extract_if.rs | 4 +- library/alloc/src/vec/into_iter.rs | 4 +- library/alloc/src/vec/mod.rs | 48 ++++---- library/alloc/src/vec/peek_mut.rs | 2 +- library/alloc/src/vec/splice.rs | 2 +- library/alloctests/lib.rs | 2 +- library/alloctests/tests/boxed.rs | 7 -- library/alloctests/tests/lib.rs | 2 +- .../alloctests/tests/vec_deque_alloc_error.rs | 2 +- library/core/src/alloc/mod.rs | 64 +++++++--- library/core/src/ptr/non_null.rs | 2 +- library/std/src/alloc.rs | 6 +- library/std/src/collections/hash/map.rs | 36 +++--- library/std/src/collections/hash/set.rs | 38 +++--- library/std/src/lib.rs | 2 +- .../{allocator-api.md => allocator-ext.md} | 2 +- src/tools/clippy/tests/ui/vec_box_sized.rs | 2 +- .../tests/fail/alloc/alloc_error_handler.rs | 2 +- .../fail/alloc/alloc_error_handler_custom.rs | 2 +- .../fail/alloc/alloc_error_handler_no_std.rs | 2 +- .../tests/fail/alloc/global_system_mixup.rs | 2 +- .../validity/box-custom-alloc-dangling-ptr.rs | 2 +- .../box-custom-alloc-invalid-alloc.rs | 2 +- .../tests/panic/alloc_error_handler_hook.rs | 2 +- .../pass/both_borrows/basic_aliasing_model.rs | 2 +- .../tests/pass/box-custom-alloc-aliasing.rs | 2 +- src/tools/miri/tests/pass/box-custom-alloc.rs | 2 +- src/tools/miri/tests/pass/global_allocator.rs | 2 +- src/tools/miri/tests/pass/heap_allocator.rs | 2 +- .../tests/pass/tree_borrows/tree-borrows.rs | 2 +- tests/incremental/lint-unused-features.rs | 7 +- .../mir-opt/box_conditional_drop_allocator.rs | 2 +- .../issue_117368_print_invalid_constant.rs | 2 +- tests/run-make/std-core-cycle/bar.rs | 2 +- tests/ui/README.md | 2 +- tests/ui/allocator/alloc-shrink-oob-read.rs | 1 - tests/ui/allocator/auxiliary/custom.rs | 2 +- tests/ui/allocator/custom.rs | 1 - tests/ui/allocator/dyn-incompatible.rs | 2 +- tests/ui/allocator/xcrate-use.rs | 1 - tests/ui/array-slice-vec/vec-res-add.stderr | 1 + .../async-drop/async-drop-box-allocator.rs | 2 +- tests/ui/box/alloc-unstable-fail.rs | 6 - tests/ui/box/alloc-unstable-fail.stderr | 13 -- tests/ui/box/alloc-unstable.rs | 4 +- tests/ui/box/issue-95036.rs | 2 +- tests/ui/box/large-allocator-ice.rs | 2 +- tests/ui/box/leak-alloc.rs | 4 +- tests/ui/box/leak-alloc.stderr | 8 +- ...parison_instead_of_pattern_matching.stderr | 4 + .../debuginfo-box-with-large-allocator.rs | 2 +- .../ui/drop/box-conditional-drop-allocator.rs | 1 - .../could-not-resolve-issue-121503.rs | 2 +- tests/ui/lint/must_not_suspend/allocator.rs | 2 +- .../unused-features/used-library-features.rs | 4 +- tests/ui/lto/issue-100772.rs | 2 +- .../implicit-const-deref.stderr | 1 + tests/ui/pattern/issue-115599.stderr | 1 + tests/ui/pattern/pattern-tyvar-2.stderr | 1 + .../ui/precondition-checks/vec-from-parts.rs | 2 +- .../precondition-checks/vec-from-raw-parts.rs | 2 +- tests/ui/regions/regions-mock-codegen.rs | 1 - .../suggest-vec-allocator-api.rs | 9 -- .../suggest-vec-allocator-api.stderr | 53 --------- tests/ui/traits/const-traits/issue-102156.rs | 2 +- 87 files changed, 410 insertions(+), 460 deletions(-) rename src/doc/unstable-book/src/library-features/{allocator-api.md => allocator-ext.md} (96%) delete mode 100644 tests/ui/box/alloc-unstable-fail.rs delete mode 100644 tests/ui/box/alloc-unstable-fail.stderr delete mode 100644 tests/ui/stability-attribute/suggest-vec-allocator-api.rs delete mode 100644 tests/ui/stability-attribute/suggest-vec-allocator-api.stderr diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index be8538acd30eb..082bb576b9745 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -10,9 +10,10 @@ #![allow(internal_features)] #![allow(rustc::default_hash_types)] #![allow(rustc::potential_query_instability)] +#![cfg_attr(bootstrap, feature(allocator_api))] +#![cfg_attr(not(bootstrap), feature(allocator_ext))] #![cfg_attr(test, feature(test))] #![deny(unsafe_op_in_unsafe_fn)] -#![feature(allocator_api)] #![feature(ascii_char)] #![feature(ascii_char_variants)] #![feature(auto_traits)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index a018951a94770..da83f41cd3e71 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -27,8 +27,9 @@ // tidy-alphabetical-start #![allow(internal_features)] #![allow(rustc::direct_use_of_rustc_type_ir)] +#![cfg_attr(bootstrap, feature(allocator_api))] #![cfg_attr(doc, feature(intra_doc_pointers))] -#![feature(allocator_api)] +#![cfg_attr(not(bootstrap), feature(allocator_ext))] #![feature(associated_type_defaults)] #![feature(box_as_ptr)] #![feature(closure_track_caller)] diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 9e7a13922e9e2..109ecce778626 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -51,16 +51,16 @@ unsafe extern "Rust" { /// /// Note: while this type is unstable, the functionality it provides can be /// accessed through the [free functions in `alloc`](self#functions). -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[derive(Copy, Clone, Default, Debug)] // the compiler needs to know when a Box uses the global allocator vs a custom one #[lang = "global_alloc_ty"] pub struct Global; -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl core::alloc::AllocatorClone for Global {} -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl core::alloc::PinSafeAllocator for Global {} /// Allocates memory with the global allocator. @@ -446,7 +446,7 @@ impl Global { } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] unsafe impl const Allocator for Global { #[inline] diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 40a8582e22bb1..aea6aeefa83bd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -235,7 +235,7 @@ pub use thin::ThinBox; // compiler or ICEs will happen. pub struct Box< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, >(Unique, A); /// Monomorphic function for allocating an uninit `Box`. @@ -366,12 +366,12 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// let five = Box::try_new(5)?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new(x: T) -> Result { Self::try_new_in(x, Global) @@ -383,7 +383,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// let mut five = Box::::try_new_uninit()?; /// // Deferred initialization: @@ -393,7 +393,7 @@ impl Box { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_uninit() -> Result>, AllocError> { Box::try_new_uninit_in(Global) @@ -408,7 +408,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// let zero = Box::::try_new_zeroed()?; /// let zero = unsafe { zero.assume_init() }; @@ -418,7 +418,7 @@ impl Box { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_zeroed() -> Result>, AllocError> { Box::try_new_zeroed_in(Global) @@ -509,14 +509,12 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] - /// /// use std::alloc::System; /// /// let five = Box::new_in(5, System); /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[must_use] #[inline] pub fn new_in(x: T, alloc: A) -> Self @@ -536,14 +534,14 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// /// let five = Box::try_new_in(5, System)?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_in(x: T, alloc: A) -> Result where @@ -559,7 +557,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -570,7 +568,7 @@ impl Box { /// /// assert_eq!(*five, 5) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[cfg(not(no_global_oom_handling))] #[must_use] pub fn new_uninit_in(alloc: A) -> Box, A> @@ -592,7 +590,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -604,7 +602,7 @@ impl Box { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_uninit_in(alloc: A) -> Result, A>, AllocError> where A: Allocator, @@ -627,7 +625,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -638,7 +636,7 @@ impl Box { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[cfg(not(no_global_oom_handling))] #[must_use] pub fn new_zeroed_in(alloc: A) -> Box, A> @@ -664,7 +662,7 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -676,7 +674,7 @@ impl Box { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError> where A: Allocator, @@ -701,13 +699,13 @@ impl Box { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::alloc::System; /// /// let x = Box::pin_in(1, System); /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] #[inline(always)] pub fn pin_in(x: T, alloc: A) -> Pin @@ -803,13 +801,12 @@ impl Box { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] /// /// let hello: Box = Box::try_clone_from_ref("hello")?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] #[inline] pub fn try_clone_from_ref(src: &T) -> Result, AllocError> { @@ -826,7 +823,7 @@ impl Box { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -834,7 +831,7 @@ impl Box { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] #[inline] pub fn clone_from_ref_in(src: &T, alloc: A) -> Box { @@ -853,7 +850,7 @@ impl Box { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -861,7 +858,7 @@ impl Box { /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] #[inline] pub fn try_clone_from_ref_in(src: &T, alloc: A) -> Result, AllocError> { @@ -948,7 +945,7 @@ impl Box<[T]> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// let mut values = Box::<[u32]>::try_new_uninit_slice(3)?; /// // Deferred initialization: @@ -960,7 +957,7 @@ impl Box<[T]> { /// assert_eq!(*values, [1, 2, 3]); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_uninit_slice(len: usize) -> Result]>, AllocError> { let ptr = if T::IS_ZST || len == 0 { @@ -984,7 +981,7 @@ impl Box<[T]> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// let values = Box::<[u32]>::try_new_zeroed_slice(3)?; /// let values = unsafe { values.assume_init() }; @@ -994,7 +991,7 @@ impl Box<[T]> { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_zeroed_slice(len: usize) -> Result]>, AllocError> { let ptr = if T::IS_ZST || len == 0 { @@ -1016,7 +1013,7 @@ impl Box<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1030,7 +1027,7 @@ impl Box<[T], A> { /// assert_eq!(*values, [1, 2, 3]) /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) } @@ -1045,7 +1042,7 @@ impl Box<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1057,7 +1054,7 @@ impl Box<[T], A> { /// /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) } @@ -1069,7 +1066,7 @@ impl Box<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1083,7 +1080,7 @@ impl Box<[T], A> { /// assert_eq!(*values, [1, 2, 3]); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_uninit_slice_in( len: usize, @@ -1110,7 +1107,7 @@ impl Box<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1122,7 +1119,7 @@ impl Box<[T], A> { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_zeroed_slice_in( len: usize, @@ -1529,7 +1526,7 @@ impl Box { /// Recreate a `Box` which was previously converted to a raw pointer /// using [`Box::into_raw_with_allocator`]: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1539,7 +1536,7 @@ impl Box { /// ``` /// Manually create a `Box` from scratch by using the system allocator: /// ``` - /// #![feature(allocator_api, slice_ptr_get)] + /// #![feature(allocator_ext, slice_ptr_get)] /// /// use std::alloc::{Allocator, Layout, System}; /// @@ -1556,7 +1553,7 @@ impl Box { /// /// [memory layout]: self#memory-layout /// [considerations for unsafe code]: self#considerations-for-unsafe-code - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self { Box(unsafe { Unique::new_unchecked(raw) }, alloc) @@ -1586,7 +1583,7 @@ impl Box { /// Recreate a `Box` which was previously converted to a `NonNull` pointer /// using [`Box::into_non_null_with_allocator`]: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1596,7 +1593,7 @@ impl Box { /// ``` /// Manually create a `Box` from scratch by using the system allocator: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::{Allocator, Layout, System}; /// @@ -1612,7 +1609,7 @@ impl Box { /// /// [memory layout]: self#memory-layout /// [considerations for unsafe code]: self#considerations-for-unsafe-code - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] // #[unstable(feature = "box_vec_non_null", issue = "130364")] #[inline] pub unsafe fn from_non_null_in(raw: NonNull, alloc: A) -> Self { @@ -1640,7 +1637,7 @@ impl Box { /// Converting the raw pointer back into a `Box` with [`Box::from_raw_in`] /// for automatic cleanup: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1651,7 +1648,7 @@ impl Box { /// Manual cleanup by explicitly running the destructor and deallocating /// the memory: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::{Allocator, Layout, System}; /// use std::ptr::{self, NonNull}; @@ -1667,7 +1664,7 @@ impl Box { /// /// [memory layout]: self#memory-layout #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) { let mut b = mem::ManuallyDrop::new(b); @@ -1702,7 +1699,7 @@ impl Box { /// Converting the `NonNull` pointer back into a `Box` with /// [`Box::from_non_null_in`] for automatic cleanup: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1713,7 +1710,7 @@ impl Box { /// Manual cleanup by explicitly running the destructor and deallocating /// the memory: /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::{Allocator, Layout, System}; /// @@ -1727,7 +1724,7 @@ impl Box { /// /// [memory layout]: self#memory-layout #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] // #[unstable(feature = "box_vec_non_null", issue = "130364")] #[inline] pub fn into_non_null_with_allocator(b: Self) -> (NonNull, A) { @@ -1844,7 +1841,7 @@ impl Box { /// Note: this is an associated function, which means that you have /// to call it as `Box::allocator(&b)` instead of `b.allocator()`. This /// is so that there is no conflict with a method on the inner type. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(b: &Self) -> &A { &b.1 @@ -2420,7 +2417,7 @@ impl Future for Box { } #[stable(feature = "box_error", since = "1.8.0")] -impl Error for Box { +impl Error for Box { #[allow(deprecated)] fn cause(&self) -> Option<&dyn Error> { Error::cause(&**self) @@ -2435,7 +2432,7 @@ impl Error for Box { } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe impl Allocator for Box { #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { @@ -2487,7 +2484,7 @@ unsafe impl Allocator for Box { } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl AllocatorClone for Box where T: AllocatorClone, @@ -2496,7 +2493,7 @@ where { } -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl AllocatorEq for Box where T: AllocatorEq + ?Sized, diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index 22c3d89e3ccdb..dd9442e6ca167 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -78,7 +78,6 @@ impl ThinBox { /// # Examples /// /// ``` - /// #![feature(allocator_api)] /// #![feature(thin_box)] /// use std::boxed::ThinBox; /// diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 34de563fe4f33..87d5f87f88992 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -273,7 +273,7 @@ use crate::vec::{self, Vec}; #[cfg_attr(not(test), rustc_diagnostic_item = "BinaryHeap")] pub struct BinaryHeap< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { data: Vec, } @@ -289,7 +289,7 @@ pub struct BinaryHeap< pub struct PeekMut< 'a, T: 'a + Ord, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { heap: &'a mut BinaryHeap, // If a set_len + sift_down are required, this is Some. If a &mut T has not @@ -484,7 +484,7 @@ impl fmt::Debug for BinaryHeap { struct RebuildOnDrop< 'a, T: Ord, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { heap: &'a mut BinaryHeap, rebuild_from: usize, @@ -545,14 +545,15 @@ impl BinaryHeap { /// Basic usage: /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// use std::collections::BinaryHeap; /// /// let heap : BinaryHeap = BinaryHeap::new_in(System); /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] #[must_use] pub const fn new_in(alloc: A) -> BinaryHeap { BinaryHeap { data: Vec::new_in(alloc) } @@ -569,14 +570,14 @@ impl BinaryHeap { /// Basic usage: /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// use std::collections::BinaryHeap; /// /// let heap: BinaryHeap = BinaryHeap::with_capacity_in(10, System); /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] pub fn with_capacity_in(capacity: usize, alloc: A) -> BinaryHeap { BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) } @@ -1419,7 +1420,7 @@ impl BinaryHeap { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(&self) -> &A { self.data.allocator() @@ -1679,14 +1680,14 @@ impl FusedIterator for Iter<'_, T> {} #[derive(Clone)] pub struct IntoIter< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { iter: vec::IntoIter, } impl IntoIter { /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { self.iter.allocator() } @@ -1784,14 +1785,14 @@ unsafe impl AsVecIntoIter for IntoIter { #[derive(Clone, Debug)] pub struct IntoIterSorted< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { inner: BinaryHeap, } impl IntoIterSorted { /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { self.inner.allocator() } @@ -1833,14 +1834,14 @@ unsafe impl TrustedLen for IntoIterSorted {} pub struct Drain< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { iter: vec::Drain<'a, T, A>, } impl Drain<'_, T, A> { /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { self.iter.allocator() } @@ -1890,14 +1891,14 @@ impl FusedIterator for Drain<'_, T, A> {} pub struct DrainSorted< 'a, T: Ord, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { inner: &'a mut BinaryHeap, } impl<'a, T: Ord, A: Allocator> DrainSorted<'a, T, A> { /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { self.inner.allocator() } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 7d994359ed48b..8a2be47a048ff 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -189,7 +189,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; pub struct BTreeMap< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { root: Option>, length: usize, @@ -444,7 +444,7 @@ impl<'a, K: 'a, V: 'a> Default for IterMut<'a, K, V> { pub struct IntoIter< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { range: LazyLeafRange, length: usize, @@ -552,7 +552,7 @@ impl fmt::Debug for ValuesMut<'_, K, V> { pub struct IntoKeys< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { inner: IntoIter, } @@ -575,7 +575,7 @@ impl fmt::Debug for IntoKeys { pub struct IntoValues< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { inner: IntoIter, } @@ -682,7 +682,6 @@ impl BTreeMap { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] /// # #![feature(btreemap_alloc)] /// /// use std::collections::BTreeMap; @@ -2133,7 +2132,7 @@ pub struct ExtractIf< V, R, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pred: F, inner: ExtractIfInner<'a, K, V, R>, @@ -3143,7 +3142,7 @@ pub struct CursorMut< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A = Global, > { inner: CursorMutKey<'a, K, V, A>, } @@ -3181,7 +3180,7 @@ pub struct CursorMutKey< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A = Global, > { // If current is None then it means the tree has not been allocated yet. current: Option, K, V, marker::Leaf>, marker::Edge>>, diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index b99fbb5e84bd6..0f00e4e29ae68 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -20,7 +20,7 @@ pub enum Entry< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { /// A vacant entry. #[stable(feature = "rust1", since = "1.0.0")] @@ -48,7 +48,7 @@ pub struct VacantEntry< 'a, K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pub(super) key: K, /// `None` for a (empty) map without root @@ -76,7 +76,7 @@ pub struct OccupiedEntry< 'a, K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pub(super) handle: Handle, K, V, marker::LeafOrInternal>, marker::KV>, pub(super) dormant_map: DormantMutRef<'a, BTreeMap>, @@ -104,7 +104,7 @@ pub struct OccupiedError< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { /// The entry in the map that was already occupied. pub entry: OccupiedEntry<'a, K, V, A>, diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 2a483b3d3982e..8926328168ce8 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -77,7 +77,7 @@ pub use self::entry::{Entry, OccupiedEntry, VacantEntry}; #[cfg_attr(not(test), rustc_diagnostic_item = "BTreeSet")] pub struct BTreeSet< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { map: BTreeMap, } @@ -153,7 +153,7 @@ impl fmt::Debug for Iter<'_, T> { #[derive(Debug)] pub struct IntoIter< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { iter: super::map::IntoIter, } @@ -183,7 +183,7 @@ pub struct Range<'a, T: 'a> { pub struct Difference< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { inner: DifferenceInner<'a, T, A>, } @@ -257,7 +257,7 @@ impl fmt::Debug for SymmetricDifference<'_, T> { pub struct Intersection< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { inner: IntersectionInner<'a, T, A>, } @@ -353,7 +353,6 @@ impl BTreeSet { /// /// ``` /// # #![allow(unused_mut)] - /// # #![feature(allocator_api)] /// # #![feature(btreemap_alloc)] /// /// use std::collections::BTreeSet; @@ -1559,7 +1558,7 @@ pub struct ExtractIf< T, R, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pred: F, inner: super::map::ExtractIfInner<'a, T, SetValZST, R>, @@ -2156,8 +2155,11 @@ impl Debug for Cursor<'_, K> { /// A `CursorMut` is created with the [`BTreeSet::lower_bound_mut`] and [`BTreeSet::upper_bound_mut`] /// methods. #[unstable(feature = "btree_cursors", issue = "107540")] -pub struct CursorMut<'a, K: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A = Global> -{ +pub struct CursorMut< + 'a, + K: 'a, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A = Global, +> { inner: super::map::CursorMut<'a, K, SetValZST, A>, } @@ -2193,7 +2195,7 @@ impl Debug for CursorMut<'_, K, A> { pub struct CursorMutKey< 'a, K: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A = Global, > { inner: super::map::CursorMutKey<'a, K, SetValZST, A>, } diff --git a/library/alloc/src/collections/btree/set/entry.rs b/library/alloc/src/collections/btree/set/entry.rs index a60d22f9ece71..e734490ec9494 100644 --- a/library/alloc/src/collections/btree/set/entry.rs +++ b/library/alloc/src/collections/btree/set/entry.rs @@ -42,7 +42,7 @@ use crate::alloc::{Allocator, Global}; pub enum Entry< 'a, T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { /// An occupied entry. /// @@ -133,7 +133,7 @@ impl Debug for Entry<'_, T, A> { pub struct OccupiedEntry< 'a, T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pub(super) inner: map::OccupiedEntry<'a, T, SetValZST, A>, } @@ -175,7 +175,7 @@ impl Debug for OccupiedEntry<'_, T, A> { pub struct VacantEntry< 'a, T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + Clone = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + Clone = Global, > { pub(super) inner: map::VacantEntry<'a, T, SetValZST, A>, } diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index ca3b2eab30402..d21aa43a0fa52 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -49,7 +49,7 @@ mod tests; #[rustc_insignificant_dtor] pub struct LinkedList< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { head: Option>>, tail: Option>>, @@ -140,7 +140,7 @@ impl fmt::Debug for IterMut<'_, T> { #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { list: LinkedList, } @@ -504,7 +504,7 @@ impl LinkedList { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// use std::collections::LinkedList; @@ -512,7 +512,7 @@ impl LinkedList { /// let list: LinkedList = LinkedList::new_in(System); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub const fn new_in(alloc: A) -> Self { LinkedList { head: None, tail: None, len: 0, alloc, marker: PhantomData } } @@ -1335,7 +1335,7 @@ impl Default for IterMut<'_, T> { pub struct Cursor< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { index: usize, current: Option>>, @@ -1371,7 +1371,7 @@ impl fmt::Debug for Cursor<'_, T, A> { pub struct CursorMut< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { index: usize, current: Option>>, @@ -1952,7 +1952,7 @@ pub struct ExtractIf< 'a, T: 'a, F: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { list: &'a mut LinkedList, it: Option>>, diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index da4b803c64d56..766a833684b7d 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -18,7 +18,7 @@ use crate::alloc::{Allocator, Global}; pub struct Drain< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead diff --git a/library/alloc/src/collections/vec_deque/extract_if.rs b/library/alloc/src/collections/vec_deque/extract_if.rs index 19439dfb4f05d..e9ac8e6fae0fa 100644 --- a/library/alloc/src/collections/vec_deque/extract_if.rs +++ b/library/alloc/src/collections/vec_deque/extract_if.rs @@ -27,7 +27,7 @@ pub struct ExtractIf< 'a, T, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { vec: &'a mut VecDeque, /// The index of the item that will be inspected by the next call to `next`. @@ -57,7 +57,7 @@ impl<'a, T, F, A: Allocator> ExtractIf<'a, T, F, A> { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(&self) -> &A { self.vec.allocator() diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index e18b85dd4b694..104d4ed98d5a5 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -18,7 +18,7 @@ use crate::alloc::{Allocator, Global}; #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { inner: VecDeque, } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 5a900db9d1ce8..7fefa6b1e2200 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -103,7 +103,7 @@ mod tests; #[rustc_insignificant_dtor] pub struct VecDeque< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -879,7 +879,7 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// /// use std::collections::VecDeque; /// use std::alloc::Global; @@ -887,7 +887,7 @@ impl VecDeque { /// let deque: VecDeque = VecDeque::new_in(Global); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub const fn new_in(alloc: A) -> VecDeque { VecDeque { head: WrappedIndex::zero(), len: 0, buf: RawVec::new_in(alloc) } } @@ -897,14 +897,14 @@ impl VecDeque { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// /// use std::collections::VecDeque; /// use std::alloc::Global; /// /// let deque: VecDeque = VecDeque::with_capacity_in(10, Global); /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { VecDeque { head: WrappedIndex::zero(), @@ -1543,7 +1543,7 @@ impl VecDeque { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(&self) -> &A { self.buf.allocator() diff --git a/library/alloc/src/collections/vec_deque/splice.rs b/library/alloc/src/collections/vec_deque/splice.rs index a29e9c3742564..bdf6a9fc68b45 100644 --- a/library/alloc/src/collections/vec_deque/splice.rs +++ b/library/alloc/src/collections/vec_deque/splice.rs @@ -24,7 +24,7 @@ use crate::vec::Vec; pub struct Splice< 'a, I: Iterator + 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + 'a = Global, > { pub(super) drain: Drain<'a, I::Item, A>, pub(super) replace_with: I, diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 3f0c0ab3080c5..63b39069e2713 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -86,7 +86,7 @@ // // Library features: // tidy-alphabetical-start -#![feature(allocator_api)] +#![feature(allocator_ext)] #![feature(array_into_iter_constructors)] #![feature(ascii_char)] #![feature(async_fn_traits)] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a79f1d8992caf..f178d49458d9c 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -319,7 +319,7 @@ fn rc_inner_layout_for_value_layout(layout: Layout) -> Layout { pub struct Rc< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { ptr: NonNull>, phantom: PhantomData>, @@ -554,13 +554,13 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::Rc; /// /// let five = Rc::try_new(5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new(value: T) -> Result, AllocError> { // There is an implicit weak pointer owned by all the strong // pointers, which ensures that the weak destructor never frees @@ -583,7 +583,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// @@ -597,7 +597,7 @@ impl Rc { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_uninit() -> Result>, AllocError> { unsafe { Ok(Rc::from_ptr(Rc::try_allocate_for_layout( @@ -617,7 +617,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// @@ -629,7 +629,7 @@ impl Rc { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_zeroed() -> Result>, AllocError> { unsafe { Ok(Rc::from_ptr(Rc::try_allocate_for_layout( @@ -742,7 +742,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -750,7 +750,7 @@ impl Rc { /// let five = Rc::new_in(5, System); /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_in(value: T, alloc: A) -> Rc { // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable. @@ -767,7 +767,7 @@ impl Rc { /// /// ``` /// #![feature(get_mut_unchecked)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -784,7 +784,7 @@ impl Rc { /// assert_eq!(*five, 5) /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_uninit_in(alloc: A) -> Rc, A> { unsafe { @@ -808,7 +808,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -821,7 +821,7 @@ impl Rc { /// /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_zeroed_in(alloc: A) -> Rc, A> { unsafe { @@ -866,7 +866,7 @@ impl Rc { /// [`new_cyclic`]: Rc::new_cyclic /// [`upgrade`]: Weak::upgrade #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_cyclic_in(data_fn: F, alloc: A) -> Rc where F: FnOnce(&Weak) -> T, @@ -920,14 +920,14 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::Rc; /// use std::alloc::System; /// /// let five = Rc::try_new_in(5, System); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_in(value: T, alloc: A) -> Result { // There is an implicit weak pointer owned by all the strong @@ -947,7 +947,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// #![feature(get_mut_unchecked)] /// /// use std::rc::Rc; @@ -965,7 +965,7 @@ impl Rc { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_uninit_in(alloc: A) -> Result, A>, AllocError> { unsafe { @@ -990,7 +990,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1003,7 +1003,7 @@ impl Rc { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError> { unsafe { @@ -1021,7 +1021,7 @@ impl Rc { /// Constructs a new `Pin>` in the provided allocator. If `T` does not implement `Unpin`, then /// `value` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn pin_in(value: T, alloc: A) -> Pin where @@ -1173,7 +1173,7 @@ impl Rc<[T], A> { /// /// ``` /// #![feature(get_mut_unchecked)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1192,7 +1192,7 @@ impl Rc<[T], A> { /// assert_eq!(*values, [1, 2, 3]) /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Rc<[mem::MaybeUninit], A> { unsafe { Rc::from_ptr_in(Rc::allocate_for_slice_in(len, &alloc), alloc) } @@ -1207,7 +1207,7 @@ impl Rc<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1220,7 +1220,7 @@ impl Rc<[T], A> { /// /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Rc<[mem::MaybeUninit], A> { unsafe { @@ -1328,14 +1328,13 @@ impl Rc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] /// use std::rc::Rc; /// /// let hello: Rc = Rc::try_clone_from_ref("hello")?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_clone_from_ref(value: &T) -> Result, AllocError> { Rc::try_clone_from_ref_in(value, Global) } @@ -1348,7 +1347,7 @@ impl Rc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::Rc; /// use std::alloc::System; /// @@ -1356,7 +1355,7 @@ impl Rc { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn clone_from_ref_in(value: &T, alloc: A) -> Rc { // `in_progress` drops the allocation if we panic before finishing initializing it. let mut in_progress: UniqueRcUninit = UniqueRcUninit::new(value, alloc); @@ -1378,7 +1377,7 @@ impl Rc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::Rc; /// use std::alloc::System; /// @@ -1386,7 +1385,7 @@ impl Rc { /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_clone_from_ref_in(value: &T, alloc: A) -> Result, AllocError> { // `in_progress` drops the allocation if we panic before finishing initializing it. let mut in_progress: UniqueRcUninit = UniqueRcUninit::try_new(value, alloc)?; @@ -1617,7 +1616,7 @@ impl Rc { /// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This /// is so that there is no conflict with a method on the inner type. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(this: &Self) -> &A { &this.alloc } @@ -1630,7 +1629,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::Rc; /// use std::alloc::System; /// @@ -1641,7 +1640,7 @@ impl Rc { /// assert_eq!(&*x, "hello"); /// ``` #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn into_raw_with_allocator(this: Self) -> (*const T, A) { let this = mem::ManuallyDrop::new(this); let ptr = Self::as_ptr(&this); @@ -1712,7 +1711,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1734,7 +1733,7 @@ impl Rc { /// Convert a slice back into its original array: /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1747,7 +1746,7 @@ impl Rc { /// assert_eq!(&*x, &[1, 2, 3]); /// } /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self { let offset = unsafe { data_offset(ptr) }; @@ -1833,7 +1832,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1851,7 +1850,7 @@ impl Rc { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn increment_strong_count_in(ptr: *const T, alloc: A) where A: AllocatorClone, @@ -1879,7 +1878,7 @@ impl Rc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::rc::Rc; /// use std::alloc::System; @@ -1897,7 +1896,7 @@ impl Rc { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn decrement_strong_count_in(ptr: *const T, alloc: A) { unsafe { drop(Rc::from_raw_in(ptr, alloc)) }; } @@ -2972,7 +2971,7 @@ impl From for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Rc { +impl From> for Rc { /// Move a boxed object to a new, reference counted, allocation. /// /// # Example @@ -2984,7 +2983,7 @@ impl From> for Rc { /// assert_eq!(1, *shared); /// ``` #[inline] - fn from(v: Box) -> Rc { + fn from(v: Box) -> Rc { Rc::from_box_in(v) } } @@ -3191,7 +3190,7 @@ impl> ToRcSlice for I { #[rustc_diagnostic_item = "RcWeak"] pub struct Weak< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // This is a `NonNull` to allow optimizing the size of this type in enums, // but it is not necessarily a valid pointer. @@ -3256,7 +3255,7 @@ impl Weak { /// assert!(empty.upgrade().is_none()); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(alloc: A) -> Weak { Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc } } @@ -3359,7 +3358,7 @@ impl Weak { impl Weak { /// Returns a reference to the underlying allocator. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { &self.alloc } @@ -3418,7 +3417,7 @@ impl Weak { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::rc::{Rc, Weak}; /// use std::alloc::System; /// @@ -3437,7 +3436,7 @@ impl Weak { /// [`as_ptr`]: Weak::as_ptr #[must_use = "losing the pointer will leak memory"] #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn into_raw_with_allocator(self) -> (*const T, A) { let this = mem::ManuallyDrop::new(self); let result = this.as_ptr(); @@ -3489,7 +3488,7 @@ impl Weak { /// [`upgrade`]: Weak::upgrade /// [`new`]: Weak::new #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self { // See Weak::as_ptr for context on how the input pointer is derived. @@ -3922,7 +3921,7 @@ fn data_offset_alignment(alignment: Alignment) -> usize { #[unstable(feature = "unique_rc_arc", issue = "112566")] pub struct UniqueRc< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { ptr: NonNull>, // Define the ownership of `RcInner` for drop-check @@ -4548,7 +4547,7 @@ impl Drop for UniqueRcUninit { } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe impl Allocator for Rc { #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 39e72e383eacb..6721693e4771a 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -381,7 +381,7 @@ impl [T] { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -392,7 +392,7 @@ impl [T] { #[cfg(not(no_global_oom_handling))] #[rustc_allow_incoherent_impl] #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 064790bbf16e4..0080fa10a4ca3 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -795,7 +795,7 @@ pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box { } #[doc(hidden)] -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn from_boxed_utf8_unchecked_in( v: Box<[u8], A>, ) -> Box { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 8c717a7b2e242..cb5e507365db1 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -268,7 +268,7 @@ macro_rules! acquire { )] pub struct Arc< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { ptr: NonNull>, phantom: PhantomData>, @@ -347,7 +347,7 @@ impl Arc { #[rustc_diagnostic_item = "ArcWeak"] pub struct Weak< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // This is a `NonNull` to allow optimizing the size of this type in enums, // but it is not necessarily a valid pointer. @@ -565,7 +565,7 @@ impl Arc { } /// Constructs a new `Pin>`, return an error if allocation fails. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_pin(data: T) -> Result>, AllocError> { unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) } @@ -576,13 +576,13 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::sync::Arc; /// /// let five = Arc::try_new(5)?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new(data: T) -> Result, AllocError> { // Start the weak pointer count as 1 which is the weak pointer that's @@ -601,7 +601,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// @@ -615,7 +615,7 @@ impl Arc { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_uninit() -> Result>, AllocError> { unsafe { Ok(Arc::from_ptr(Arc::try_allocate_for_layout( @@ -635,7 +635,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature( allocator_api)] + /// #![feature( allocator_ext)] /// /// use std::sync::Arc; /// @@ -647,7 +647,7 @@ impl Arc { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_new_zeroed() -> Result>, AllocError> { unsafe { Ok(Arc::from_ptr(Arc::try_allocate_for_layout( @@ -752,7 +752,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -761,7 +761,7 @@ impl Arc { /// ``` #[inline] #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(data: T, alloc: A) -> Arc { // Start the weak pointer count as 1 which is the weak pointer that's // held by all the strong pointers (kinda), see std/rc.rs for more info @@ -783,7 +783,7 @@ impl Arc { /// /// ``` /// #![feature(get_mut_unchecked)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -800,7 +800,7 @@ impl Arc { /// assert_eq!(*five, 5) /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_uninit_in(alloc: A) -> Arc, A> { unsafe { @@ -824,7 +824,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -837,7 +837,7 @@ impl Arc { /// /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_zeroed_in(alloc: A) -> Arc, A> { unsafe { @@ -883,7 +883,7 @@ impl Arc { /// [`upgrade`]: Weak::upgrade #[cfg(not(no_global_oom_handling))] #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_cyclic_in(data_fn: F, alloc: A) -> Arc where F: FnOnce(&Weak) -> T, @@ -947,7 +947,7 @@ impl Arc { /// Constructs a new `Pin>` in the provided allocator. If `T` does not implement `Unpin`, /// then `data` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn pin_in(data: T, alloc: A) -> Pin> where @@ -959,7 +959,7 @@ impl Arc { /// Constructs a new `Pin>` in the provided allocator, return an error if allocation /// fails. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_pin_in(data: T, alloc: A) -> Result>, AllocError> where A: 'static, @@ -972,7 +972,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -980,7 +980,7 @@ impl Arc { /// let five = Arc::try_new_in(5, System)?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_in(data: T, alloc: A) -> Result, AllocError> { // Start the weak pointer count as 1 which is the weak pointer that's @@ -1003,7 +1003,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// #![feature(get_mut_unchecked)] /// /// use std::sync::Arc; @@ -1021,7 +1021,7 @@ impl Arc { /// assert_eq!(*five, 5); /// # Ok::<(), std::alloc::AllocError>(()) /// ``` - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_uninit_in(alloc: A) -> Result, A>, AllocError> { unsafe { @@ -1046,7 +1046,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -1059,7 +1059,7 @@ impl Arc { /// ``` /// /// [zeroed]: mem::MaybeUninit::zeroed - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError> { unsafe { @@ -1320,7 +1320,7 @@ impl Arc<[T], A> { /// /// ``` /// #![feature(get_mut_unchecked)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -1339,7 +1339,7 @@ impl Arc<[T], A> { /// assert_eq!(*values, [1, 2, 3]) /// ``` #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit], A> { unsafe { Arc::from_ptr_in(Arc::allocate_for_slice_in(len, &alloc), alloc) } @@ -1354,7 +1354,7 @@ impl Arc<[T], A> { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -1367,7 +1367,7 @@ impl Arc<[T], A> { /// /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit], A> { unsafe { @@ -1476,14 +1476,13 @@ impl Arc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] /// use std::sync::Arc; /// /// let hello: Arc = Arc::try_clone_from_ref("hello")?; /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_clone_from_ref(value: &T) -> Result, AllocError> { Arc::try_clone_from_ref_in(value, Global) } @@ -1496,7 +1495,7 @@ impl Arc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::sync::Arc; /// use std::alloc::System; /// @@ -1504,7 +1503,7 @@ impl Arc { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn clone_from_ref_in(value: &T, alloc: A) -> Arc { // `in_progress` drops the allocation if we panic before finishing initializing it. let mut in_progress: UniqueArcUninit = UniqueArcUninit::new(value, alloc); @@ -1526,7 +1525,7 @@ impl Arc { /// /// ``` /// #![feature(clone_from_ref)] - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::sync::Arc; /// use std::alloc::System; /// @@ -1534,7 +1533,7 @@ impl Arc { /// # Ok::<(), std::alloc::AllocError>(()) /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] - //#[unstable(feature = "allocator_api", issue = "32838")] + //#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn try_clone_from_ref_in(value: &T, alloc: A) -> Result, AllocError> { // `in_progress` drops the allocation if we panic before finishing initializing it. let mut in_progress: UniqueArcUninit = UniqueArcUninit::try_new(value, alloc)?; @@ -1771,7 +1770,7 @@ impl Arc { /// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This /// is so that there is no conflict with a method on the inner type. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(this: &Self) -> &A { &this.alloc } @@ -1784,7 +1783,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::sync::Arc; /// use std::alloc::System; /// @@ -1795,7 +1794,7 @@ impl Arc { /// assert_eq!(&*x, "hello"); /// ``` #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn into_raw_with_allocator(this: Self) -> (*const T, A) { let this = mem::ManuallyDrop::new(this); let ptr = Self::as_ptr(&this); @@ -1867,7 +1866,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -1889,7 +1888,7 @@ impl Arc { /// Convert a slice back into its original array: /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -1903,7 +1902,7 @@ impl Arc { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self { unsafe { let offset = data_offset(ptr); @@ -2039,7 +2038,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -2059,7 +2058,7 @@ impl Arc { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn increment_strong_count_in(ptr: *const T, alloc: A) where A: AllocatorClone, @@ -2088,7 +2087,7 @@ impl Arc { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Arc; /// use std::alloc::System; @@ -2108,7 +2107,7 @@ impl Arc { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn decrement_strong_count_in(ptr: *const T, alloc: A) { unsafe { drop(Arc::from_raw_in(ptr, alloc)) }; } @@ -2982,7 +2981,7 @@ impl Weak { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::sync::Weak; /// use std::alloc::System; @@ -2991,7 +2990,7 @@ impl Weak { /// assert!(empty.upgrade().is_none()); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(alloc: A) -> Weak { Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc } } @@ -3089,7 +3088,7 @@ impl Weak { impl Weak { /// Returns a reference to the underlying allocator. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn allocator(&self) -> &A { &self.alloc } @@ -3148,7 +3147,7 @@ impl Weak { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::sync::{Arc, Weak}; /// use std::alloc::System; /// @@ -3166,7 +3165,7 @@ impl Weak { /// [`from_raw_in`]: Weak::from_raw_in /// [`as_ptr`]: Weak::as_ptr #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn into_raw_with_allocator(self) -> (*const T, A) { let this = mem::ManuallyDrop::new(self); let result = this.as_ptr(); @@ -3218,7 +3217,7 @@ impl Weak { /// [`into_raw`]: Weak::into_raw /// [`upgrade`]: Weak::upgrade #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self { // See Weak::as_ptr for context on how the input pointer is derived. @@ -4010,7 +4009,7 @@ impl From for Arc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Arc { +impl From> for Arc { /// Move a boxed object to a new, reference-counted allocation. /// /// # Example @@ -4022,7 +4021,7 @@ impl From> for Arc { /// assert_eq!("eggplant", &shared[..]); /// ``` #[inline] - fn from(v: Box) -> Arc { + fn from(v: Box) -> Arc { Arc::from_box_in(v) } } @@ -4372,7 +4371,7 @@ impl core::error::Error for Arc { #[unstable(feature = "unique_rc_arc", issue = "112566")] pub struct UniqueArc< T: ?Sized, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { ptr: NonNull>, // Define the ownership of `ArcInner` for drop-check @@ -4762,7 +4761,7 @@ impl UniqueArc { #[cfg(not(no_global_oom_handling))] #[unstable(feature = "unique_rc_arc", issue = "112566")] #[must_use] - // #[unstable(feature = "allocator_api", issue = "32838")] + // #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(data: T, alloc: A) -> Self { let (ptr, alloc) = Box::into_unique(Box::new_in( ArcInner { @@ -4917,7 +4916,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for UniqueArc { } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe impl Allocator for Arc { #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index d12dea20b33cb..0038c7918c1d5 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -21,7 +21,7 @@ use crate::alloc::{Allocator, Global}; pub struct Drain< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + 'a = Global, > { /// Index of tail to preserve pub(super) tail_start: usize, @@ -58,7 +58,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[must_use] #[inline] pub fn allocator(&self) -> &A { diff --git a/library/alloc/src/vec/extract_if.rs b/library/alloc/src/vec/extract_if.rs index a4c4c19682195..557eaeac5cb76 100644 --- a/library/alloc/src/vec/extract_if.rs +++ b/library/alloc/src/vec/extract_if.rs @@ -22,7 +22,7 @@ pub struct ExtractIf< 'a, T, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -50,7 +50,7 @@ impl<'a, T, F, A: Allocator> ExtractIf<'a, T, F, A> { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(&self) -> &A { self.vec.allocator() diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 97e4912596b94..5b79ddaf6bf79 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -44,7 +44,7 @@ macro non_null { #[rustc_insignificant_dtor] pub struct IntoIter< T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -108,7 +108,7 @@ impl IntoIter { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[inline] pub fn allocator(&self) -> &A { &self.alloc diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 130f72b0ee485..f3ca6abacdc09 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -435,7 +435,10 @@ mod spec_extend; #[rustc_insignificant_dtor] #[doc(alias = "list")] #[doc(alias = "vector")] -pub struct Vec { +pub struct Vec< + T, + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] A: Allocator = Global, +> { buf: RawVec, len: usize, } @@ -944,7 +947,7 @@ const impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -972,7 +975,7 @@ const impl Vec { /// assert_eq!(vec_units.capacity(), usize::MAX); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 } } @@ -1058,14 +1061,13 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] - /// /// use std::alloc::System; /// /// let vec: Vec = Vec::new_in(System); /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] pub const fn new_in(alloc: A) -> Self { Vec { buf: RawVec::new_in(alloc), len: 0 } } @@ -1082,7 +1084,7 @@ impl Vec { /// Returns an error if the capacity exceeds `isize::MAX` _bytes_, /// or if the allocator reports allocation failure. #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] // #[unstable(feature = "try_with_capacity", issue = "91913")] pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { Ok(Vec { buf: RawVec::try_with_capacity_in(capacity, alloc)?, len: 0 }) @@ -1136,7 +1138,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1165,7 +1167,7 @@ impl Vec { /// Using memory that was allocated elsewhere: /// /// ```rust - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::{AllocError, Allocator, Global, Layout}; /// @@ -1188,8 +1190,8 @@ impl Vec { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] pub const unsafe fn from_raw_parts_in( ptr: *mut T, length: usize, @@ -1253,7 +1255,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1280,7 +1282,7 @@ impl Vec { /// Using memory that was allocated elsewhere: /// /// ```rust - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::{AllocError, Allocator, Global, Layout}; /// @@ -1303,8 +1305,8 @@ impl Vec { /// } /// ``` #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] // #[unstable(feature = "box_vec_non_null", issue = "130364")] pub const unsafe fn from_parts_in( ptr: NonNull, @@ -1337,7 +1339,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1358,8 +1360,8 @@ impl Vec { /// assert_eq!(rebuilt, [4294967295, 0, 1]); /// ``` #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] pub const fn into_raw_parts_with_alloc(self) -> (*mut T, usize, usize, A) { let mut me = ManuallyDrop::new(self); let len = me.len(); @@ -1387,7 +1389,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// /// use std::alloc::System; /// @@ -1408,8 +1410,8 @@ impl Vec { /// assert_eq!(rebuilt, [4294967295, 0, 1]); /// ``` #[must_use = "losing the pointer will leak memory"] - #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] + #[rustc_const_unstable(feature = "allocator_ext", issue = "32838")] // #[unstable(feature = "box_vec_non_null", issue = "130364")] pub const fn into_parts_with_alloc(self) -> (NonNull, usize, usize, A) { let (ptr, len, capacity, alloc) = self.into_raw_parts_with_alloc(); @@ -2123,7 +2125,7 @@ impl Vec { } /// Returns a reference to the underlying allocator. - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] #[inline] pub const fn allocator(&self) -> &A { @@ -3717,7 +3719,7 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec { ::from_elem(elem, n, alloc) } diff --git a/library/alloc/src/vec/peek_mut.rs b/library/alloc/src/vec/peek_mut.rs index 979bcaa1111d5..c1da49eddb75d 100644 --- a/library/alloc/src/vec/peek_mut.rs +++ b/library/alloc/src/vec/peek_mut.rs @@ -15,7 +15,7 @@ use crate::fmt; pub struct PeekMut< 'a, T, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { vec: &'a mut Vec, } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 99ebcb4ada296..b82b2d728624d 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -20,7 +20,7 @@ use crate::alloc::{Allocator, Global}; pub struct Splice< 'a, I: Iterator + 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator + 'a = Global, > { pub(super) drain: Drain<'a, I::Item, A>, pub(super) replace_with: I, diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index db643ccb7a4e6..9783ac16a6c23 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -14,7 +14,7 @@ // // Library features: // tidy-alphabetical-start -#![feature(allocator_api)] +#![feature(allocator_ext)] #![feature(array_into_iter_constructors)] #![feature(char_internals)] #![feature(const_alloc_error)] diff --git a/library/alloctests/tests/boxed.rs b/library/alloctests/tests/boxed.rs index a0c3cb55edcc6..82c73fc75a4ca 100644 --- a/library/alloctests/tests/boxed.rs +++ b/library/alloctests/tests/boxed.rs @@ -211,13 +211,6 @@ unsafe impl Allocator for ConstAllocator { } Ok(new_ptr) } - - fn by_ref(&self) -> &Self - where - Self: Sized, - { - self - } } #[allow(unused)] diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 1414835058b9a..4fa38efb789c0 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api)] +#![feature(allocator_ext)] #![feature(binary_heap_pop_if)] #![feature(const_heap)] #![feature(deque_extend_front)] diff --git a/library/alloctests/tests/vec_deque_alloc_error.rs b/library/alloctests/tests/vec_deque_alloc_error.rs index 21a9118a05bd6..863af31e1cd1e 100644 --- a/library/alloctests/tests/vec_deque_alloc_error.rs +++ b/library/alloctests/tests/vec_deque_alloc_error.rs @@ -1,4 +1,4 @@ -#![feature(alloc_error_hook, allocator_api)] +#![feature(alloc_error_hook, allocator_ext)] use std::alloc::{AllocError, Allocator, Layout, System, set_alloc_error_hook}; use std::collections::VecDeque; diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index eabe7f2e9f24a..170d9c22ff15e 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -27,19 +27,15 @@ use crate::ptr::{self, NonNull}; /// that may be due to resource exhaustion or to /// something wrong when combining the given input arguments with this /// allocator. -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct AllocError; -#[unstable( - feature = "allocator_api", - reason = "the precise API and guarantees it provides may be tweaked.", - issue = "32838" -)] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] impl Error for AllocError {} // (we need this for downstream impl of trait Error) -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] impl fmt::Display for AllocError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("memory allocation failed") @@ -100,8 +96,6 @@ impl fmt::Display for AllocError { /// (For example, the type `&'a T` becomes invalid when `'a` expires. /// More generally, a type becomes invalid when any of its lifetime parameters has expired.) /// -/// Copying, cloning, or moving the allocator must not invalidate memory blocks returned from it. -/// A copied or cloned allocator must behave like the original allocator. /// /// A memory block which is [*currently allocated*] may be passed to /// any method of the allocator that accepts such an argument. @@ -132,7 +126,7 @@ impl fmt::Display for AllocError { /// Implementors of the trait must guarantee that none of the methods on this trait unwind. /// /// [*currently allocated*]: #currently-allocated-memory -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] #[rustc_dyn_incompatible_trait] pub const unsafe trait Allocator { @@ -162,6 +156,7 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] fn allocate(&self, layout: Layout) -> Result, AllocError>; /// Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. @@ -179,6 +174,7 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] fn allocate_zeroed(&self, layout: Layout) -> Result, AllocError> { let ptr = self.allocate(layout)?; // SAFETY: `alloc` returns a valid memory block @@ -200,6 +196,7 @@ pub const unsafe trait Allocator { /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); /// Attempts to extend the memory block. @@ -240,6 +237,7 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe fn grow( &self, ptr: NonNull, @@ -303,6 +301,7 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe fn grow_zeroed( &self, ptr: NonNull, @@ -367,6 +366,7 @@ pub const unsafe trait Allocator { /// call the [`handle_alloc_error`] function, rather than directly invoking `panic!` or similar. /// /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html + #[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe fn shrink( &self, ptr: NonNull, @@ -399,7 +399,7 @@ pub const unsafe trait Allocator { /// (i.e. is is possible to free memory with one that was allocated with the other). /// Further, mutable accesses such as moving or dropping the allocator must not invalidate /// its currently allocated blocks at least so long as clones exist. -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe trait AllocatorClone: Allocator + Clone {} /// Marks a type's [`PartialEq`] implementation as sound with regard to [`Allocator`]. @@ -407,7 +407,7 @@ pub unsafe trait AllocatorClone: Allocator + Clone {} /// (i.e. is is possible to free memory with one that was allocated with the other), and /// that the two allocators behave "as if" they are clones of each other as per /// [`AllocatorClone`]. -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe trait AllocatorEq: Allocator + PartialEq where T: ?Sized + AllocatorEq, @@ -419,10 +419,10 @@ where /// global state, e.g. `System` or `Global`. /// /// [`Pin`]: ../../core/pin/struct.Pin.html -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub unsafe trait PinSafeAllocator: Allocator + 'static {} -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_heap", issue = "79597")] unsafe impl const Allocator for &A where @@ -478,7 +478,7 @@ where } } -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe impl Allocator for &mut A where A: Allocator + ?Sized, @@ -532,3 +532,37 @@ where unsafe { (**self).shrink(ptr, old_layout, new_layout) } } } + +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] +#[diagnostic::do_not_recommend] +unsafe impl GlobalAlloc for A { + default unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + self.allocate(layout).map(|p| p.as_ptr().cast::()).ok().unwrap_or(ptr::null_mut()) + } + + default unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + // SAFETY: Upheld by caller + unsafe { self.deallocate(NonNull::new_unchecked(ptr), layout) } + } + + default unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + self.allocate_zeroed(layout) + .map(|p| p.as_ptr().cast::()) + .ok() + .unwrap_or(ptr::null_mut()) + } + + default unsafe fn realloc(&self, ptr: *mut u8, old_layout: Layout, new_size: usize) -> *mut u8 { + // SAFETY: Upheld by caller + unsafe { + let new_layout = Layout::from_size_align_unchecked(new_size, old_layout.align()); + let ptr = NonNull::new_unchecked(ptr); + let ret = if new_size > old_layout.size() { + self.grow(ptr, old_layout, new_layout) + } else { + self.shrink(ptr, old_layout, new_layout) + }; + ret.map(|p| p.as_ptr().cast::()).ok().unwrap_or(ptr::null_mut()) + } + } +} diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index f165e235611b8..643455ec19a99 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1611,7 +1611,7 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust - /// #![feature(allocator_api, ptr_as_uninit)] + /// #![feature(ptr_as_uninit)] /// /// use std::alloc::{Allocator, Layout, Global}; /// use std::mem::MaybeUninit; diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index f44008c791468..f7390342253dc 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -138,10 +138,10 @@ pub use alloc_crate::alloc::*; #[derive(Debug, Default, Copy, Clone)] pub struct System; -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl core::alloc::AllocatorClone for System {} -#[unstable(feature = "allocator_api", issue = "32838")] +#[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] unsafe impl core::alloc::PinSafeAllocator for System {} impl System { @@ -213,7 +213,7 @@ impl System { // The Allocator impl checks the layout size to be non-zero and forwards to the GlobalAlloc impl, // which is in `std::sys::*::alloc`. -#[unstable(feature = "allocator_api", issue = "32838")] +#[stable(feature = "allocator_api", since = "CURRENT_RUSTC_VERSION")] unsafe impl Allocator for System { #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index a7a9b7901d7f4..72422331ab2ee 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -247,7 +247,7 @@ pub struct HashMap< K, V, S = RandomState, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::HashMap, } @@ -300,7 +300,7 @@ impl HashMap { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::collections::HashMap; /// use std::alloc::Global; /// @@ -308,7 +308,7 @@ impl HashMap { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(alloc: A) -> Self { HashMap::with_hasher_in(Default::default(), alloc) } @@ -323,7 +323,7 @@ impl HashMap { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::collections::HashMap; /// use std::alloc::Global; /// @@ -331,7 +331,7 @@ impl HashMap { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { HashMap::with_capacity_and_hasher_in(capacity, Default::default(), alloc) } @@ -419,7 +419,7 @@ impl HashMap { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::alloc::Global; /// use std::collections::HashMap; /// use std::hash::RandomState; @@ -429,7 +429,7 @@ impl HashMap { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self { HashMap { base: base::HashMap::with_hasher_in(hash_builder, alloc) } } @@ -452,7 +452,7 @@ impl HashMap { /// # Examples /// /// ``` - /// #![feature(allocator_api)] + /// #![feature(allocator_ext)] /// use std::alloc::Global; /// use std::collections::HashMap; /// use std::hash::RandomState; @@ -462,7 +462,7 @@ impl HashMap { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_and_hasher_in(capacity: usize, hash_builder: S, alloc: A) -> Self { HashMap { base: base::HashMap::with_capacity_and_hasher_in(capacity, hash_builder, alloc) } } @@ -1661,7 +1661,7 @@ impl Default for IterMut<'_, K, V> { pub struct IntoIter< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::IntoIter, } @@ -1799,7 +1799,7 @@ pub struct Drain< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::Drain<'a, K, V, A>, } @@ -1836,7 +1836,7 @@ pub struct ExtractIf< K, V, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::ExtractIf<'a, K, V, F, A>, } @@ -1893,7 +1893,7 @@ impl Default for ValuesMut<'_, K, V> { pub struct IntoKeys< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { inner: IntoIter, } @@ -1927,7 +1927,7 @@ impl Default for IntoKeys { pub struct IntoValues< K, V, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { inner: IntoIter, } @@ -1951,7 +1951,7 @@ pub enum Entry< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { /// An occupied entry. #[stable(feature = "rust1", since = "1.0.0")] @@ -1979,7 +1979,7 @@ pub struct OccupiedEntry< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::RustcOccupiedEntry<'a, K, V, A>, } @@ -2001,7 +2001,7 @@ pub struct VacantEntry< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::RustcVacantEntry<'a, K, V, A>, } @@ -2022,7 +2022,7 @@ pub struct OccupiedError< 'a, K: 'a, V: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { /// The entry in the map that was already occupied. pub entry: OccupiedEntry<'a, K, V, A>, diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index fadd62652c62d..ab5973dbaa440 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -126,7 +126,7 @@ use crate::ops::{BitAnd, BitOr, BitXor, Sub}; pub struct HashSet< T, S = RandomState, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::HashSet, } @@ -179,7 +179,7 @@ impl HashSet { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::alloc::Global; /// use std::collections::HashSet; /// @@ -187,7 +187,7 @@ impl HashSet { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn new_in(alloc: A) -> HashSet { HashSet::with_hasher_in(Default::default(), alloc) } @@ -201,7 +201,7 @@ impl HashSet { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::collections::HashSet; /// use std::alloc::Global; /// @@ -209,7 +209,7 @@ impl HashSet { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_in(capacity: usize, alloc: A) -> HashSet { HashSet::with_capacity_and_hasher_in(capacity, Default::default(), alloc) } @@ -297,7 +297,7 @@ impl HashSet { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::alloc::Global; /// use std::collections::HashSet; /// use std::hash::RandomState; @@ -307,7 +307,7 @@ impl HashSet { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_hasher_in(hasher: S, alloc: A) -> HashSet { HashSet { base: base::HashSet::with_hasher_in(hasher, alloc) } } @@ -330,7 +330,7 @@ impl HashSet { /// # Examples /// /// ``` - /// # #![feature(allocator_api)] + /// # #![feature(allocator_ext)] /// use std::alloc::Global; /// use std::collections::HashSet; /// use std::hash::RandomState; @@ -340,7 +340,7 @@ impl HashSet { /// ``` #[inline] #[must_use] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] pub fn with_capacity_and_hasher_in(capacity: usize, hasher: S, alloc: A) -> HashSet { HashSet { base: base::HashSet::with_capacity_and_hasher_in(capacity, hasher, alloc) } } @@ -1468,7 +1468,7 @@ impl Default for Iter<'_, K> { #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter< K, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::IntoIter, } @@ -1502,7 +1502,7 @@ impl Default for IntoIter { pub struct Drain< 'a, K: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::Drain<'a, K, A>, } @@ -1529,7 +1529,7 @@ pub struct ExtractIf< 'a, K, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::ExtractIf<'a, K, F, A>, } @@ -1558,7 +1558,7 @@ pub struct Intersection< 'a, T: 'a, S: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // iterator of the first set iter: Iter<'a, T>, @@ -1590,7 +1590,7 @@ pub struct Difference< 'a, T: 'a, S: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { // iterator of the first set iter: Iter<'a, T>, @@ -1622,7 +1622,7 @@ pub struct SymmetricDifference< 'a, T: 'a, S: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { iter: Chain, Difference<'a, T, S, A>>, } @@ -1651,7 +1651,7 @@ pub struct Union< 'a, T: 'a, S: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { iter: Chain, Difference<'a, T, S, A>>, } @@ -2145,7 +2145,7 @@ pub enum Entry< 'a, T, S, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { /// An occupied entry. /// @@ -2237,7 +2237,7 @@ pub struct OccupiedEntry< 'a, T, S, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::OccupiedEntry<'a, T, S, A>, } @@ -2282,7 +2282,7 @@ pub struct VacantEntry< 'a, T, S, - #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + #[unstable(feature = "allocator_ext", issue = "32838", implied_by = "allocator_api")] A: Allocator = Global, > { base: base::VacantEntry<'a, T, S, A>, } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8086cab34cf44..fc1c8ac1defb4 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -388,7 +388,7 @@ // // Library features (alloc): // tidy-alphabetical-start -#![feature(allocator_api)] +#![feature(allocator_ext)] #![feature(clone_from_ref)] #![feature(get_mut_unchecked)] #![feature(map_try_insert)] diff --git a/src/doc/unstable-book/src/library-features/allocator-api.md b/src/doc/unstable-book/src/library-features/allocator-ext.md similarity index 96% rename from src/doc/unstable-book/src/library-features/allocator-api.md rename to src/doc/unstable-book/src/library-features/allocator-ext.md index 9f045ce08a433..f1e7551bdfa08 100644 --- a/src/doc/unstable-book/src/library-features/allocator-api.md +++ b/src/doc/unstable-book/src/library-features/allocator-ext.md @@ -1,4 +1,4 @@ -# `allocator_api` +# `allocator_ext` The tracking issue for this feature is [#32838] diff --git a/src/tools/clippy/tests/ui/vec_box_sized.rs b/src/tools/clippy/tests/ui/vec_box_sized.rs index 897add423b6d4..1f58d59877f1f 100644 --- a/src/tools/clippy/tests/ui/vec_box_sized.rs +++ b/src/tools/clippy/tests/ui/vec_box_sized.rs @@ -1,7 +1,7 @@ //@no-rustfix #![allow(dead_code)] -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{AllocError, Allocator, Layout}; use std::ptr::NonNull; diff --git a/src/tools/miri/tests/fail/alloc/alloc_error_handler.rs b/src/tools/miri/tests/fail/alloc/alloc_error_handler.rs index 35b8e20e56b3c..71e4eadc4e0b8 100644 --- a/src/tools/miri/tests/fail/alloc/alloc_error_handler.rs +++ b/src/tools/miri/tests/fail/alloc/alloc_error_handler.rs @@ -1,5 +1,5 @@ //@error-in-other-file: aborted -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::*; diff --git a/src/tools/miri/tests/fail/alloc/alloc_error_handler_custom.rs b/src/tools/miri/tests/fail/alloc/alloc_error_handler_custom.rs index 8d41002735cc9..72f45be61b299 100644 --- a/src/tools/miri/tests/fail/alloc/alloc_error_handler_custom.rs +++ b/src/tools/miri/tests/fail/alloc/alloc_error_handler_custom.rs @@ -1,7 +1,7 @@ //@compile-flags: -Cpanic=abort #![feature(core_intrinsics)] #![feature(alloc_error_handler)] -#![feature(allocator_api)] +#![feature(allocator_ext)] #![no_std] #![no_main] diff --git a/src/tools/miri/tests/fail/alloc/alloc_error_handler_no_std.rs b/src/tools/miri/tests/fail/alloc/alloc_error_handler_no_std.rs index f73f8e3e7e196..c7c51c95e9c26 100644 --- a/src/tools/miri/tests/fail/alloc/alloc_error_handler_no_std.rs +++ b/src/tools/miri/tests/fail/alloc/alloc_error_handler_no_std.rs @@ -1,7 +1,7 @@ //@compile-flags: -Cpanic=abort #![feature(core_intrinsics)] #![feature(alloc_error_handler)] -#![feature(allocator_api)] +#![feature(allocator_ext)] #![no_std] #![no_main] diff --git a/src/tools/miri/tests/fail/alloc/global_system_mixup.rs b/src/tools/miri/tests/fail/alloc/global_system_mixup.rs index bbf069b7a2def..f80ac906fd952 100644 --- a/src/tools/miri/tests/fail/alloc/global_system_mixup.rs +++ b/src/tools/miri/tests/fail/alloc/global_system_mixup.rs @@ -8,7 +8,7 @@ //@normalize-stderr-test: "alloc::[A-Za-z]+::" -> "alloc::PLATFORM::" //@normalize-stderr-test: "alloc/[A-Za-z]+.rs" -> "alloc/PLATFORM.rs" -#![feature(allocator_api, slice_ptr_get)] +#![feature(allocator_ext, slice_ptr_get)] use std::alloc::{Allocator, Global, Layout, System}; diff --git a/src/tools/miri/tests/fail/validity/box-custom-alloc-dangling-ptr.rs b/src/tools/miri/tests/fail/validity/box-custom-alloc-dangling-ptr.rs index 5fb81296494e5..cc0bd3fc3a22c 100644 --- a/src/tools/miri/tests/fail/validity/box-custom-alloc-dangling-ptr.rs +++ b/src/tools/miri/tests/fail/validity/box-custom-alloc-dangling-ptr.rs @@ -1,5 +1,5 @@ //! Ensure that a box with a custom allocator detects when the pointer is dangling. -#![feature(allocator_api)] +#![feature(allocator_ext)] // This should not need the aliasing model. //@compile-flags: -Zmiri-disable-stacked-borrows use std::alloc::Layout; diff --git a/src/tools/miri/tests/fail/validity/box-custom-alloc-invalid-alloc.rs b/src/tools/miri/tests/fail/validity/box-custom-alloc-invalid-alloc.rs index 101a550593f90..0ed54d0112dd4 100644 --- a/src/tools/miri/tests/fail/validity/box-custom-alloc-invalid-alloc.rs +++ b/src/tools/miri/tests/fail/validity/box-custom-alloc-invalid-alloc.rs @@ -1,5 +1,5 @@ //! Ensure that a box with a custom allocator detects when the allocator itself is invalid. -#![feature(allocator_api)] +#![feature(allocator_ext)] // This should not need the aliasing model. //@compile-flags: -Zmiri-disable-stacked-borrows use std::alloc::Layout; diff --git a/src/tools/miri/tests/panic/alloc_error_handler_hook.rs b/src/tools/miri/tests/panic/alloc_error_handler_hook.rs index a1eadb45fd13b..f7516ce86e883 100644 --- a/src/tools/miri/tests/panic/alloc_error_handler_hook.rs +++ b/src/tools/miri/tests/panic/alloc_error_handler_hook.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api, alloc_error_hook)] +#![feature(allocator_ext, alloc_error_hook)] use std::alloc::*; diff --git a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs index 5689ad0e62e2b..02378bc9d4011 100644 --- a/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs +++ b/src/tools/miri/tests/pass/both_borrows/basic_aliasing_model.rs @@ -1,7 +1,7 @@ //@revisions: stack tree tree_implicit_writes //@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes //@[tree]compile-flags: -Zmiri-tree-borrows -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{Layout, alloc, dealloc}; use std::cell::Cell; use std::ptr; diff --git a/src/tools/miri/tests/pass/box-custom-alloc-aliasing.rs b/src/tools/miri/tests/pass/box-custom-alloc-aliasing.rs index 06ddda278765a..afbc3bcc05124 100644 --- a/src/tools/miri/tests/pass/box-custom-alloc-aliasing.rs +++ b/src/tools/miri/tests/pass/box-custom-alloc-aliasing.rs @@ -5,7 +5,7 @@ //@revisions: stack tree tree_implicit_writes //@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes //@[tree]compile-flags: -Zmiri-tree-borrows -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{AllocError, Allocator, Layout}; use std::cell::{Cell, UnsafeCell}; diff --git a/src/tools/miri/tests/pass/box-custom-alloc.rs b/src/tools/miri/tests/pass/box-custom-alloc.rs index 9a1a2f935921e..409e646dc85ec 100644 --- a/src/tools/miri/tests/pass/box-custom-alloc.rs +++ b/src/tools/miri/tests/pass/box-custom-alloc.rs @@ -1,7 +1,7 @@ //@revisions: stack tree tree_implicit_writes //@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes //@[tree]compile-flags: -Zmiri-tree-borrows -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{AllocError, Allocator, Layout}; use std::cell::Cell; diff --git a/src/tools/miri/tests/pass/global_allocator.rs b/src/tools/miri/tests/pass/global_allocator.rs index 9a40c322b366e..92609a7e6d858 100644 --- a/src/tools/miri/tests/pass/global_allocator.rs +++ b/src/tools/miri/tests/pass/global_allocator.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api, slice_ptr_get)] +#![feature(allocator_ext, slice_ptr_get)] use std::alloc::{Allocator as _, Global, GlobalAlloc, Layout, System}; diff --git a/src/tools/miri/tests/pass/heap_allocator.rs b/src/tools/miri/tests/pass/heap_allocator.rs index 2c38dcb49f1ce..95e02e5470523 100644 --- a/src/tools/miri/tests/pass/heap_allocator.rs +++ b/src/tools/miri/tests/pass/heap_allocator.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api, slice_ptr_get)] +#![feature(allocator_ext, slice_ptr_get)] use std::alloc::{Allocator, Global, Layout, System}; use std::ptr::NonNull; diff --git a/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs b/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs index 4bcaf823e99ca..4c2a1cab97dac 100644 --- a/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs +++ b/src/tools/miri/tests/pass/tree_borrows/tree-borrows.rs @@ -1,7 +1,7 @@ //@revisions: tree tree_implicit_writes //@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows-implicit-writes //@compile-flags: -Zmiri-tree-borrows -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::{mem, ptr}; diff --git a/tests/incremental/lint-unused-features.rs b/tests/incremental/lint-unused-features.rs index 0bf9730727f74..f2daed52de836 100644 --- a/tests/incremental/lint-unused-features.rs +++ b/tests/incremental/lint-unused-features.rs @@ -10,8 +10,8 @@ // Used library features #![feature(error_iter)] //[bfail]~^ ERROR feature `error_iter` is declared but not used -#![cfg_attr(all(), feature(allocator_api))] -//[bfail]~^ ERROR feature `allocator_api` is declared but not used +#![cfg_attr(all(), feature(allocator_ext))] +//[bfail]~^ ERROR feature `allocator_ext` is declared but not used macro m() {} pub fn use_decl_macro() { @@ -28,8 +28,7 @@ pub fn use_error_iter(e: &(dyn std::error::Error + 'static)) { #[cfg(rpass)] pub fn use_allocator_api() { - use std::alloc::Global; - let _ = Vec::::new_in(Global); + let _a: Box; } fn main() {} diff --git a/tests/mir-opt/box_conditional_drop_allocator.rs b/tests/mir-opt/box_conditional_drop_allocator.rs index 741c396b0c2d7..766c81340f6e8 100644 --- a/tests/mir-opt/box_conditional_drop_allocator.rs +++ b/tests/mir-opt/box_conditional_drop_allocator.rs @@ -1,7 +1,7 @@ //@ skip-filecheck //@ test-mir-pass: ElaborateDrops //@ needs-unwind -#![feature(allocator_api)] +#![feature(allocator_ext)] // Regression test for #131082. // Testing that the allocator of a Box is dropped in conditional drops diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs index 08347f71b4239..1613b8cb8c2c2 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs @@ -3,7 +3,7 @@ // EMIT_MIR_FOR_EACH_BIT_WIDTH // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{Allocator, Global, Layout}; diff --git a/tests/run-make/std-core-cycle/bar.rs b/tests/run-make/std-core-cycle/bar.rs index 9f5e7c29bddd7..d1a3c5089dddb 100644 --- a/tests/run-make/std-core-cycle/bar.rs +++ b/tests/run-make/std-core-cycle/bar.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api)] +#![feature(allocator_ext)] #![crate_type = "rlib"] use std::alloc::*; diff --git a/tests/ui/README.md b/tests/ui/README.md index f76cd507056fe..30e3a0e25ca76 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -18,7 +18,7 @@ See . ## `tests/ui/allocator` -These tests exercise `#![feature(allocator_api)]` and the `#[global_allocator]` attribute. +These tests exercise `#![feature(allocator_ext)]` and the `#[global_allocator]` attribute. See [Allocator traits and `std::heap` #32838](https://github.com/rust-lang/rust/issues/32838). diff --git a/tests/ui/allocator/alloc-shrink-oob-read.rs b/tests/ui/allocator/alloc-shrink-oob-read.rs index b9edfca3b7b51..120d327e2a344 100644 --- a/tests/ui/allocator/alloc-shrink-oob-read.rs +++ b/tests/ui/allocator/alloc-shrink-oob-read.rs @@ -4,7 +4,6 @@ //@ run-pass -#![feature(allocator_api)] #![feature(slice_ptr_get)] use std::alloc::{Allocator, Global, Layout, handle_alloc_error}; diff --git a/tests/ui/allocator/auxiliary/custom.rs b/tests/ui/allocator/auxiliary/custom.rs index b6835307dec2f..0cde0547351d2 100644 --- a/tests/ui/allocator/auxiliary/custom.rs +++ b/tests/ui/allocator/auxiliary/custom.rs @@ -1,6 +1,6 @@ //@ no-prefer-dynamic -#![feature(allocator_api)] +#![feature(allocator_ext)] #![crate_type = "rlib"] use std::alloc::{GlobalAlloc, System, Layout}; diff --git a/tests/ui/allocator/custom.rs b/tests/ui/allocator/custom.rs index 97de54dd4d6e3..eefd89c7b5a25 100644 --- a/tests/ui/allocator/custom.rs +++ b/tests/ui/allocator/custom.rs @@ -3,7 +3,6 @@ //@ aux-build:helper.rs //@ no-prefer-dynamic -#![feature(allocator_api)] #![feature(slice_ptr_get)] extern crate helper; diff --git a/tests/ui/allocator/dyn-incompatible.rs b/tests/ui/allocator/dyn-incompatible.rs index 3e4c12fd1c73d..07d59e13681fe 100644 --- a/tests/ui/allocator/dyn-incompatible.rs +++ b/tests/ui/allocator/dyn-incompatible.rs @@ -1,6 +1,6 @@ // Check that `Allocator` is dyn-incompatible, to keep the design space open. -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{Allocator, System}; diff --git a/tests/ui/allocator/xcrate-use.rs b/tests/ui/allocator/xcrate-use.rs index 5934d73981305..a2b71c4498b13 100644 --- a/tests/ui/allocator/xcrate-use.rs +++ b/tests/ui/allocator/xcrate-use.rs @@ -4,7 +4,6 @@ //@ aux-build:helper.rs //@ no-prefer-dynamic -#![feature(allocator_api)] #![feature(slice_ptr_get)] extern crate custom; diff --git a/tests/ui/array-slice-vec/vec-res-add.stderr b/tests/ui/array-slice-vec/vec-res-add.stderr index 4e13dbd0366d0..6d5ad1d3c9694 100644 --- a/tests/ui/array-slice-vec/vec-res-add.stderr +++ b/tests/ui/array-slice-vec/vec-res-add.stderr @@ -8,6 +8,7 @@ LL | let k = i + j; | note: `Vec` does not implement `Add` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec` is defined in another crate diff --git a/tests/ui/async-await/async-drop/async-drop-box-allocator.rs b/tests/ui/async-await/async-drop/async-drop-box-allocator.rs index 86ebf8a0ffd13..58aa5c422bd61 100644 --- a/tests/ui/async-await/async-drop/async-drop-box-allocator.rs +++ b/tests/ui/async-await/async-drop/async-drop-box-allocator.rs @@ -4,7 +4,7 @@ // It's used as the allocator of a `Box` which is conditionally moved out of. // Sync version is called in sync context, async version is called in async function. -#![feature(async_drop, allocator_api)] +#![feature(async_drop)] #![allow(incomplete_features)] use std::mem::ManuallyDrop; diff --git a/tests/ui/box/alloc-unstable-fail.rs b/tests/ui/box/alloc-unstable-fail.rs deleted file mode 100644 index e209af97d7f75..0000000000000 --- a/tests/ui/box/alloc-unstable-fail.rs +++ /dev/null @@ -1,6 +0,0 @@ -use std::boxed::Box; - -fn main() { - let _boxed: Box = Box::new(10); - //~^ ERROR use of unstable library feature `allocator_api` -} diff --git a/tests/ui/box/alloc-unstable-fail.stderr b/tests/ui/box/alloc-unstable-fail.stderr deleted file mode 100644 index 6ce63a7996662..0000000000000 --- a/tests/ui/box/alloc-unstable-fail.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0658]: use of unstable library feature `allocator_api` - --> $DIR/alloc-unstable-fail.rs:4:26 - | -LL | let _boxed: Box = Box::new(10); - | ^ - | - = note: see issue #32838 for more information - = help: add `#![feature(allocator_api)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/box/alloc-unstable.rs b/tests/ui/box/alloc-unstable.rs index b8c8bc0c70af4..e52c0a19dfc20 100644 --- a/tests/ui/box/alloc-unstable.rs +++ b/tests/ui/box/alloc-unstable.rs @@ -1,5 +1,7 @@ //@ run-pass -#![feature(allocator_api)] + +#![feature(allocator_ext)] + fn main() { let _boxed: Box = Box::new(10); } diff --git a/tests/ui/box/issue-95036.rs b/tests/ui/box/issue-95036.rs index f20f4b98437fd..505cb996fd57e 100644 --- a/tests/ui/box/issue-95036.rs +++ b/tests/ui/box/issue-95036.rs @@ -1,7 +1,7 @@ //@ compile-flags: -O //@ build-pass -#![feature(allocator_api)] +#![feature(allocator_ext)] #[inline(never)] pub fn by_ref(node: &mut Box<[u8; 1], &std::alloc::Global>) { diff --git a/tests/ui/box/large-allocator-ice.rs b/tests/ui/box/large-allocator-ice.rs index d5c7069cfb951..e85b308428fe4 100644 --- a/tests/ui/box/large-allocator-ice.rs +++ b/tests/ui/box/large-allocator-ice.rs @@ -1,5 +1,5 @@ //@ build-pass -#![feature(allocator_api)] +#![feature(allocator_ext)] #![allow(unused_must_use)] use std::alloc::Allocator; diff --git a/tests/ui/box/leak-alloc.rs b/tests/ui/box/leak-alloc.rs index 3f0f39f448b91..2308e0c585e3d 100644 --- a/tests/ui/box/leak-alloc.rs +++ b/tests/ui/box/leak-alloc.rs @@ -1,4 +1,4 @@ -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{AllocError, Allocator, Layout, System}; use std::ptr::NonNull; @@ -21,7 +21,7 @@ fn use_value(_: u32) {} fn main() { let alloc = Alloc {}; - let boxed = Box::new_in(10, alloc.by_ref()); + let boxed = Box::new_in(10, &alloc); let theref = Box::leak(boxed); drop(alloc); //~^ ERROR cannot move out of `alloc` because it is borrowed diff --git a/tests/ui/box/leak-alloc.stderr b/tests/ui/box/leak-alloc.stderr index bdaa9449f913e..ad8eb17fd28d0 100644 --- a/tests/ui/box/leak-alloc.stderr +++ b/tests/ui/box/leak-alloc.stderr @@ -3,8 +3,8 @@ error[E0505]: cannot move out of `alloc` because it is borrowed | LL | let alloc = Alloc {}; | ----- binding `alloc` declared here -LL | let boxed = Box::new_in(10, alloc.by_ref()); - | ----- borrow of `alloc` occurs here +LL | let boxed = Box::new_in(10, &alloc); + | ------ borrow of `alloc` occurs here LL | let theref = Box::leak(boxed); LL | drop(alloc); | ^^^^^ move out of `alloc` occurs here @@ -18,8 +18,8 @@ note: if `Alloc` implemented `Clone`, you could clone the value LL | struct Alloc {} | ^^^^^^^^^^^^ consider implementing `Clone` for this type ... -LL | let boxed = Box::new_in(10, alloc.by_ref()); - | ----- you could clone this value +LL | let boxed = Box::new_in(10, &alloc); + | ----- you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr b/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr index 38440af675feb..ab823c8fc73b9 100644 --- a/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr +++ b/tests/ui/consts/const_in_pattern/suggest_equality_comparison_instead_of_pattern_matching.stderr @@ -123,6 +123,7 @@ LL | V => {} | ^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec<()>` is not usable in patterns | @@ -143,6 +144,7 @@ LL | if let V = vec![] {} | ^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec<()>` is not usable in patterns | @@ -158,6 +160,7 @@ LL | let V = vec![] else { return; }; | ^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec<()>` is not usable in patterns | @@ -173,6 +176,7 @@ LL | let V = Vec::new() else { return; }; | ^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec<()>` is not usable in patterns | diff --git a/tests/ui/debuginfo/debuginfo-box-with-large-allocator.rs b/tests/ui/debuginfo/debuginfo-box-with-large-allocator.rs index ac857ff34a4d7..e5233c696c8a8 100644 --- a/tests/ui/debuginfo/debuginfo-box-with-large-allocator.rs +++ b/tests/ui/debuginfo/debuginfo-box-with-large-allocator.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Cdebuginfo=2 // fixes issue #94725 -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::alloc::{AllocError, Allocator, Layout}; use std::ptr::NonNull; diff --git a/tests/ui/drop/box-conditional-drop-allocator.rs b/tests/ui/drop/box-conditional-drop-allocator.rs index 8f78da16473e7..605969c58f0a0 100644 --- a/tests/ui/drop/box-conditional-drop-allocator.rs +++ b/tests/ui/drop/box-conditional-drop-allocator.rs @@ -1,5 +1,4 @@ //@ run-pass -#![feature(allocator_api)] // Regression test for #131082. // Testing that the allocator of a Box is dropped in conditional drops diff --git a/tests/ui/lifetimes/could-not-resolve-issue-121503.rs b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs index 363162370f21b..6721fde174ef9 100644 --- a/tests/ui/lifetimes/could-not-resolve-issue-121503.rs +++ b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs @@ -1,6 +1,6 @@ //@ edition:2018 -#![feature(allocator_api)] +#![feature(allocator_ext)] struct Struct; impl Struct { async fn box_ref_Struct(self: Box) -> &u32 { diff --git a/tests/ui/lint/must_not_suspend/allocator.rs b/tests/ui/lint/must_not_suspend/allocator.rs index c2ceb3297f37f..8c65c5889d987 100644 --- a/tests/ui/lint/must_not_suspend/allocator.rs +++ b/tests/ui/lint/must_not_suspend/allocator.rs @@ -1,6 +1,6 @@ //@ edition: 2021 -#![feature(must_not_suspend, allocator_api)] +#![feature(must_not_suspend, allocator_ext)] #![deny(must_not_suspend)] use std::alloc::*; diff --git a/tests/ui/lint/unused-features/used-library-features.rs b/tests/ui/lint/unused-features/used-library-features.rs index 1747c7741880e..5d18356febdc7 100644 --- a/tests/ui/lint/unused-features/used-library-features.rs +++ b/tests/ui/lint/unused-features/used-library-features.rs @@ -5,7 +5,7 @@ // Used library features #![feature(error_iter)] -#![cfg_attr(all(), feature(allocator_api))] +#![cfg_attr(all(), feature(allocator_ext))] pub fn use_error_iter(e: &(dyn std::error::Error + 'static)) { for _ in e.sources() {} @@ -13,5 +13,5 @@ pub fn use_error_iter(e: &(dyn std::error::Error + 'static)) { pub fn use_allocator_api() { use std::alloc::Global; - let _ = Vec::::new_in(Global); + let _ = Vec::::try_with_capacity_in(1, Global); } diff --git a/tests/ui/lto/issue-100772.rs b/tests/ui/lto/issue-100772.rs index e07d44e3be880..4452688c7187b 100644 --- a/tests/ui/lto/issue-100772.rs +++ b/tests/ui/lto/issue-100772.rs @@ -5,7 +5,7 @@ //@ only-x86_64-unknown-linux-gnu //@ ignore-backends: gcc -#![feature(allocator_api)] +#![feature(allocator_ext)] fn main() { let _ = Box::new_in(&[0, 1], &std::alloc::Global); diff --git a/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr b/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr index 7c176162ad184..c03137fcc4151 100644 --- a/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr +++ b/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr @@ -8,6 +8,7 @@ LL | EMPTY => {} | ^^^^^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec<()>` is not usable in patterns | diff --git a/tests/ui/pattern/issue-115599.stderr b/tests/ui/pattern/issue-115599.stderr index f776623ff75b2..280516deba14b 100644 --- a/tests/ui/pattern/issue-115599.stderr +++ b/tests/ui/pattern/issue-115599.stderr @@ -8,6 +8,7 @@ LL | if let CONST_STRING = empty_str {} | ^^^^^^^^^^^^ constant of non-structural type | --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec` is not usable in patterns | diff --git a/tests/ui/pattern/pattern-tyvar-2.stderr b/tests/ui/pattern/pattern-tyvar-2.stderr index 6676d5129872b..4761a4e829b85 100644 --- a/tests/ui/pattern/pattern-tyvar-2.stderr +++ b/tests/ui/pattern/pattern-tyvar-2.stderr @@ -8,6 +8,7 @@ LL | fn foo(t: Bar) -> isize { match t { Bar::T1(_, Some(x)) => { return x * 3; | note: `Vec` does not implement `Mul<{integer}>` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | = note: `Vec` is defined in another crate diff --git a/tests/ui/precondition-checks/vec-from-parts.rs b/tests/ui/precondition-checks/vec-from-parts.rs index ace90770360e5..2b4c3edc8b4a6 100644 --- a/tests/ui/precondition-checks/vec-from-parts.rs +++ b/tests/ui/precondition-checks/vec-from-parts.rs @@ -1,7 +1,7 @@ //@ run-crash //@ compile-flags: -Cdebug-assertions=yes //@ error-pattern: unsafe precondition(s) violated: Vec::from_parts_in requires that length <= capacity -#![feature(allocator_api)] +#![feature(allocator_ext)] use std::ptr::NonNull; diff --git a/tests/ui/precondition-checks/vec-from-raw-parts.rs b/tests/ui/precondition-checks/vec-from-raw-parts.rs index 1bc8e6ada10d9..db883d2589754 100644 --- a/tests/ui/precondition-checks/vec-from-raw-parts.rs +++ b/tests/ui/precondition-checks/vec-from-raw-parts.rs @@ -3,7 +3,7 @@ //@ error-pattern: unsafe precondition(s) violated: Vec::from_raw_parts_in requires that length <= capacity //@ revisions: vec_from_raw_parts vec_from_raw_parts_in string_from_raw_parts -#![feature(allocator_api)] +#![feature(allocator_ext)] fn main() { let ptr = std::ptr::null_mut::(); diff --git a/tests/ui/regions/regions-mock-codegen.rs b/tests/ui/regions/regions-mock-codegen.rs index 99c863640669e..0677e0fabbf6d 100644 --- a/tests/ui/regions/regions-mock-codegen.rs +++ b/tests/ui/regions/regions-mock-codegen.rs @@ -1,7 +1,6 @@ //@ run-pass #![allow(dead_code)] #![allow(non_camel_case_types)] -#![feature(allocator_api)] use std::alloc::{handle_alloc_error, Allocator, Global, Layout}; use std::ptr::NonNull; diff --git a/tests/ui/stability-attribute/suggest-vec-allocator-api.rs b/tests/ui/stability-attribute/suggest-vec-allocator-api.rs deleted file mode 100644 index 61a48c19e72ad..0000000000000 --- a/tests/ui/stability-attribute/suggest-vec-allocator-api.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let _: Vec = vec![]; //~ ERROR use of unstable library feature `allocator_api` - #[rustfmt::skip] - let _: Vec< - String, - _> = vec![]; //~ ERROR use of unstable library feature `allocator_api` - let _ = Vec::::new(); //~ ERROR use of unstable library feature `allocator_api` - let _boxed: Box = Box::new(10); //~ ERROR use of unstable library feature `allocator_api` -} diff --git a/tests/ui/stability-attribute/suggest-vec-allocator-api.stderr b/tests/ui/stability-attribute/suggest-vec-allocator-api.stderr deleted file mode 100644 index 78b7d07b60cc3..0000000000000 --- a/tests/ui/stability-attribute/suggest-vec-allocator-api.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error[E0658]: use of unstable library feature `allocator_api` - --> $DIR/suggest-vec-allocator-api.rs:2:20 - | -LL | let _: Vec = vec![]; - | ----^ - | | - | help: consider wrapping the inner types in tuple: `(u8, _)` - | - = note: see issue #32838 for more information - = help: add `#![feature(allocator_api)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: use of unstable library feature `allocator_api` - --> $DIR/suggest-vec-allocator-api.rs:6:9 - | -LL | _> = vec![]; - | ^ - | - = note: see issue #32838 for more information - = help: add `#![feature(allocator_api)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -help: consider wrapping the inner types in tuple - | -LL ~ let _: Vec<( -LL + String, -LL ~ _)> = vec![]; - | - -error[E0658]: use of unstable library feature `allocator_api` - --> $DIR/suggest-vec-allocator-api.rs:7:24 - | -LL | let _ = Vec::::new(); - | -----^ - | | - | help: consider wrapping the inner types in tuple: `(u16, _)` - | - = note: see issue #32838 for more information - = help: add `#![feature(allocator_api)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: use of unstable library feature `allocator_api` - --> $DIR/suggest-vec-allocator-api.rs:8:26 - | -LL | let _boxed: Box = Box::new(10); - | ^ - | - = note: see issue #32838 for more information - = help: add `#![feature(allocator_api)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/issue-102156.rs b/tests/ui/traits/const-traits/issue-102156.rs index bd9fdff3e4271..6a75e26f886e9 100644 --- a/tests/ui/traits/const-traits/issue-102156.rs +++ b/tests/ui/traits/const-traits/issue-102156.rs @@ -1,5 +1,5 @@ //@ edition:2015 -#![feature(allocator_api)] +#![feature(allocator_ext)] #![feature(const_trait_impl)] use core::convert::{From, TryFrom};