diff options
Diffstat (limited to 'library/alloc/src/vec.rs')
| -rw-r--r-- | library/alloc/src/vec.rs | 224 |
1 files changed, 113 insertions, 111 deletions
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 51687920928..9fffb47aa59 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -68,7 +68,7 @@ use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr::{self, NonNull}; use core::slice::{self, SliceIndex}; -use crate::alloc::{AllocRef, Global}; +use crate::alloc::{Allocator, Global}; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; use crate::collections::TryReserveError; @@ -298,7 +298,7 @@ use crate::raw_vec::RawVec; /// [`&`]: ../../std/primitive.reference.html #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")] -pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> { +pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> { buf: RawVec<T, A>, len: usize, } @@ -433,7 +433,7 @@ impl<T> Vec<T> { } } -impl<T, A: AllocRef> Vec<T, A> { +impl<T, A: Allocator> Vec<T, A> { /// Constructs a new, empty `Vec<T, A>`. /// /// The vector will not allocate until elements are pushed onto it. @@ -555,7 +555,7 @@ impl<T, A: AllocRef> Vec<T, A> { /// let p = v.as_mut_ptr(); /// let len = v.len(); /// let cap = v.capacity(); - /// let alloc = v.alloc_ref(); + /// let alloc = v.allocator(); /// /// unsafe { /// // Overwrite memory with 4, 5, 6 @@ -656,7 +656,7 @@ impl<T, A: AllocRef> Vec<T, A> { let len = me.len(); let capacity = me.capacity(); let ptr = me.as_mut_ptr(); - let alloc = unsafe { ptr::read(me.alloc_ref()) }; + let alloc = unsafe { ptr::read(me.allocator()) }; (ptr, len, capacity, alloc) } @@ -1058,8 +1058,8 @@ impl<T, A: AllocRef> Vec<T, A> { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] #[inline] - pub fn alloc_ref(&self) -> &A { - self.buf.alloc_ref() + pub fn allocator(&self) -> &A { + self.buf.allocator() } /// Forces the length of the vector to `new_len`. @@ -1620,12 +1620,12 @@ impl<T, A: AllocRef> Vec<T, A> { // the new vector can take over the original buffer and avoid the copy return mem::replace( self, - Vec::with_capacity_in(self.capacity(), self.alloc_ref().clone()), + Vec::with_capacity_in(self.capacity(), self.allocator().clone()), ); } let other_len = self.len - at; - let mut other = Vec::with_capacity_in(other_len, self.alloc_ref().clone()); + let mut other = Vec::with_capacity_in(other_len, self.allocator().clone()); // Unsafely `set_len` and copy items to `other`. unsafe { @@ -1749,7 +1749,7 @@ impl<T, A: AllocRef> Vec<T, A> { } } -impl<T: Clone, A: AllocRef> Vec<T, A> { +impl<T: Clone, A: Allocator> Vec<T, A> { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// /// If `new_len` is greater than `len`, the `Vec` is extended by the @@ -1844,7 +1844,7 @@ impl<T, F: FnMut() -> T> ExtendWith<T> for ExtendFunc<F> { } } -impl<T, A: AllocRef> Vec<T, A> { +impl<T, A: Allocator> Vec<T, A> { /// Extend the vector by `n` values, using the given generator. fn extend_with<E: ExtendWith<T>>(&mut self, n: usize, mut value: E) { self.reserve(n); @@ -1904,7 +1904,7 @@ impl Drop for SetLenOnDrop<'_> { } } -impl<T: PartialEq, A: AllocRef> Vec<T, A> { +impl<T: PartialEq, A: Allocator> Vec<T, A> { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. /// @@ -1926,7 +1926,7 @@ impl<T: PartialEq, A: AllocRef> Vec<T, A> { } } -impl<T, A: AllocRef> Vec<T, A> { +impl<T, A: Allocator> Vec<T, A> { /// Removes the first instance of `item` from the vector if the item exists. /// /// This method will be removed soon. @@ -1959,17 +1959,17 @@ pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> { #[doc(hidden)] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in<T: Clone, A: AllocRef>(elem: T, n: usize, alloc: A) -> Vec<T, A> { +pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> { <T as SpecFromElem>::from_elem(elem, n, alloc) } // Specialization trait used for Vec::from_elem trait SpecFromElem: Sized { - fn from_elem<A: AllocRef>(elem: Self, n: usize, alloc: A) -> Vec<Self, A>; + fn from_elem<A: Allocator>(elem: Self, n: usize, alloc: A) -> Vec<Self, A>; } impl<T: Clone> SpecFromElem for T { - default fn from_elem<A: AllocRef>(elem: Self, n: usize, alloc: A) -> Vec<Self, A> { + default fn from_elem<A: Allocator>(elem: Self, n: usize, alloc: A) -> Vec<Self, A> { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); v @@ -1978,7 +1978,7 @@ impl<T: Clone> SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem<A: AllocRef>(elem: i8, n: usize, alloc: A) -> Vec<i8, A> { + fn from_elem<A: Allocator>(elem: i8, n: usize, alloc: A) -> Vec<i8, A> { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -1993,7 +1993,7 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem<A: AllocRef>(elem: u8, n: usize, alloc: A) -> Vec<u8, A> { + fn from_elem<A: Allocator>(elem: u8, n: usize, alloc: A) -> Vec<u8, A> { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -2008,7 +2008,7 @@ impl SpecFromElem for u8 { impl<T: Clone + IsZero> SpecFromElem for T { #[inline] - fn from_elem<A: AllocRef>(elem: T, n: usize, alloc: A) -> Vec<T, A> { + fn from_elem<A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -2093,7 +2093,7 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> ops::Deref for Vec<T, A> { +impl<T, A: Allocator> ops::Deref for Vec<T, A> { type Target = [T]; fn deref(&self) -> &[T] { @@ -2102,17 +2102,17 @@ impl<T, A: AllocRef> ops::Deref for Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> ops::DerefMut for Vec<T, A> { +impl<T, A: Allocator> ops::DerefMut for Vec<T, A> { fn deref_mut(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Clone, A: AllocRef + Clone> Clone for Vec<T, A> { +impl<T: Clone, A: Allocator + Clone> Clone for Vec<T, A> { #[cfg(not(test))] fn clone(&self) -> Self { - let alloc = self.alloc_ref().clone(); + let alloc = self.allocator().clone(); <[T]>::to_vec_in(&**self, alloc) } @@ -2122,7 +2122,7 @@ impl<T: Clone, A: AllocRef + Clone> Clone for Vec<T, A> { // NB see the slice::hack module in slice.rs for more information #[cfg(test)] fn clone(&self) -> Self { - let alloc = self.alloc_ref().clone(); + let alloc = self.allocator().clone(); crate::slice::to_vec(&**self, alloc) } @@ -2141,7 +2141,7 @@ impl<T: Clone, A: AllocRef + Clone> Clone for Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Hash, A: AllocRef> Hash for Vec<T, A> { +impl<T: Hash, A: Allocator> Hash for Vec<T, A> { #[inline] fn hash<H: Hasher>(&self, state: &mut H) { Hash::hash(&**self, state) @@ -2153,7 +2153,7 @@ impl<T: Hash, A: AllocRef> Hash for Vec<T, A> { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl<T, I: SliceIndex<[T]>, A: AllocRef> Index<I> for Vec<T, A> { +impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> { type Output = I::Output; #[inline] @@ -2167,7 +2167,7 @@ impl<T, I: SliceIndex<[T]>, A: AllocRef> Index<I> for Vec<T, A> { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl<T, I: SliceIndex<[T]>, A: AllocRef> IndexMut<I> for Vec<T, A> { +impl<T, I: SliceIndex<[T]>, A: Allocator> IndexMut<I> for Vec<T, A> { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -2183,7 +2183,7 @@ impl<T> FromIterator<T> for Vec<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> IntoIterator for Vec<T, A> { +impl<T, A: Allocator> IntoIterator for Vec<T, A> { type Item = T; type IntoIter = IntoIter<T, A>; @@ -2204,7 +2204,7 @@ impl<T, A: AllocRef> IntoIterator for Vec<T, A> { fn into_iter(self) -> IntoIter<T, A> { unsafe { let mut me = ManuallyDrop::new(self); - let alloc = ptr::read(me.alloc_ref()); + let alloc = ptr::read(me.allocator()); let begin = me.as_mut_ptr(); let end = if mem::size_of::<T>() == 0 { arith_offset(begin as *const i8, me.len() as isize) as *const T @@ -2225,7 +2225,7 @@ impl<T, A: AllocRef> IntoIterator for Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: AllocRef> IntoIterator for &'a Vec<T, A> { +impl<'a, T, A: Allocator> IntoIterator for &'a Vec<T, A> { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2235,7 +2235,7 @@ impl<'a, T, A: AllocRef> IntoIterator for &'a Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: AllocRef> IntoIterator for &'a mut Vec<T, A> { +impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec<T, A> { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2245,7 +2245,7 @@ impl<'a, T, A: AllocRef> IntoIterator for &'a mut Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> Extend<T> for Vec<T, A> { +impl<T, A: Allocator> Extend<T> for Vec<T, A> { #[inline] fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) { <Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter()) @@ -2533,7 +2533,7 @@ trait SpecExtend<T, I> { fn spec_extend(&mut self, iter: I); } -impl<T, I, A: AllocRef> SpecExtend<T, I> for Vec<T, A> +impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A> where I: Iterator<Item = T>, { @@ -2542,7 +2542,7 @@ where } } -impl<T, I, A: AllocRef> SpecExtend<T, I> for Vec<T, A> +impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A> where I: TrustedLen<Item = T>, { @@ -2575,7 +2575,7 @@ where } } -impl<T, A: AllocRef> SpecExtend<T, IntoIter<T>> for Vec<T, A> { +impl<T, A: Allocator> SpecExtend<T, IntoIter<T>> for Vec<T, A> { fn spec_extend(&mut self, mut iterator: IntoIter<T>) { unsafe { self.append_elements(iterator.as_slice() as _); @@ -2584,7 +2584,7 @@ impl<T, A: AllocRef> SpecExtend<T, IntoIter<T>> for Vec<T, A> { } } -impl<'a, T: 'a, I, A: AllocRef + 'a> SpecExtend<&'a T, I> for Vec<T, A> +impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A> where I: Iterator<Item = &'a T>, T: Clone, @@ -2594,7 +2594,7 @@ where } } -impl<'a, T: 'a, A: AllocRef + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A> +impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A> where T: Copy, { @@ -2604,7 +2604,7 @@ where } } -impl<T, A: AllocRef> Vec<T, A> { +impl<T, A: Allocator> Vec<T, A> { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply fn extend_desugared<I: Iterator<Item = T>>(&mut self, mut iterator: I) { @@ -2739,7 +2739,7 @@ impl<T, A: AllocRef> Vec<T, A> { /// /// [`copy_from_slice`]: ../../std/primitive.slice.html#method.copy_from_slice #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: AllocRef + 'a> Extend<&'a T> for Vec<T, A> { +impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec<T, A> { fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) } @@ -2771,18 +2771,18 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A: AllocRef] Vec<T, A>, Vec<U, A>, #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: AllocRef] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: AllocRef] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: AllocRef] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } -__impl_slice_eq1! { [A: AllocRef] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } -__impl_slice_eq1! { [A: AllocRef] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } -__impl_slice_eq1! { [A: AllocRef] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } -__impl_slice_eq1! { [A: AllocRef] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator] Vec<T, A>, Vec<U, A>, #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } +__impl_slice_eq1! { [A: Allocator] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } +__impl_slice_eq1! { [A: Allocator] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } +__impl_slice_eq1! { [A: Allocator] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } +__impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: AllocRef, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: AllocRef, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? @@ -2796,7 +2796,7 @@ __impl_slice_eq1! { [A: AllocRef, const N: usize] Vec<T, A>, &[U; N], #[stable(f /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl<T: PartialOrd, A: AllocRef> PartialOrd for Vec<T, A> { +impl<T: PartialOrd, A: Allocator> PartialOrd for Vec<T, A> { #[inline] fn partial_cmp(&self, other: &Self) -> Option<Ordering> { PartialOrd::partial_cmp(&**self, &**other) @@ -2804,11 +2804,11 @@ impl<T: PartialOrd, A: AllocRef> PartialOrd for Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Eq, A: AllocRef> Eq for Vec<T, A> {} +impl<T: Eq, A: Allocator> Eq for Vec<T, A> {} /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Ord, A: AllocRef> Ord for Vec<T, A> { +impl<T: Ord, A: Allocator> Ord for Vec<T, A> { #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&**self, &**other) @@ -2816,7 +2816,7 @@ impl<T: Ord, A: AllocRef> Ord for Vec<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: AllocRef> Drop for Vec<T, A> { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> { fn drop(&mut self) { unsafe { // use drop for [T] @@ -2837,35 +2837,35 @@ impl<T> Default for Vec<T> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: fmt::Debug, A: AllocRef> fmt::Debug for Vec<T, A> { +impl<T: fmt::Debug, A: Allocator> fmt::Debug for Vec<T, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> AsRef<Vec<T, A>> for Vec<T, A> { +impl<T, A: Allocator> AsRef<Vec<T, A>> for Vec<T, A> { fn as_ref(&self) -> &Vec<T, A> { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl<T, A: AllocRef> AsMut<Vec<T, A>> for Vec<T, A> { +impl<T, A: Allocator> AsMut<Vec<T, A>> for Vec<T, A> { fn as_mut(&mut self) -> &mut Vec<T, A> { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> AsRef<[T]> for Vec<T, A> { +impl<T, A: Allocator> AsRef<[T]> for Vec<T, A> { fn as_ref(&self) -> &[T] { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl<T, A: AllocRef> AsMut<[T]> for Vec<T, A> { +impl<T, A: Allocator> AsMut<[T]> for Vec<T, A> { fn as_mut(&mut self) -> &mut [T] { self } @@ -2920,7 +2920,7 @@ where // note: test pulls in libstd, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] -impl<T, A: AllocRef> From<Box<[T], A>> for Vec<T, A> { +impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A> { fn from(s: Box<[T], A>) -> Self { let len = s.len(); Self { buf: RawVec::from_box(s), len } @@ -2930,7 +2930,7 @@ impl<T, A: AllocRef> From<Box<[T], A>> for Vec<T, A> { // note: test pulls in libstd, which causes errors here #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] -impl<T, A: AllocRef> From<Vec<T, A>> for Box<[T], A> { +impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> { fn from(v: Vec<T, A>) -> Self { v.into_boxed_slice() } @@ -2944,7 +2944,7 @@ impl From<&str> for Vec<u8> { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl<T, A: AllocRef, const N: usize> TryFrom<Vec<T, A>> for [T; N] { +impl<T, A: Allocator, const N: usize> TryFrom<Vec<T, A>> for [T; N] { type Error = Vec<T, A>; /// Gets the entire contents of the `Vec<T>` as an array, @@ -3045,8 +3045,10 @@ where /// let iter: std::vec::IntoIter<_> = v.into_iter(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub struct IntoIter<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> -{ +pub struct IntoIter< + T, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, +> { buf: NonNull<T>, phantom: PhantomData<T>, cap: usize, @@ -3056,13 +3058,13 @@ pub struct IntoIter<T, #[unstable(feature = "allocator_api", issue = "32838")] A } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl<T: fmt::Debug, A: AllocRef> fmt::Debug for IntoIter<T, A> { +impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } -impl<T, A: AllocRef> IntoIter<T, A> { +impl<T, A: Allocator> IntoIter<T, A> { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -3100,7 +3102,7 @@ impl<T, A: AllocRef> IntoIter<T, A> { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] #[inline] - pub fn alloc_ref(&self) -> &A { + pub fn allocator(&self) -> &A { &self.alloc } @@ -3126,19 +3128,19 @@ impl<T, A: AllocRef> IntoIter<T, A> { } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] -impl<T, A: AllocRef> AsRef<[T]> for IntoIter<T, A> { +impl<T, A: Allocator> AsRef<[T]> for IntoIter<T, A> { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<T: Send, A: AllocRef + Send> Send for IntoIter<T, A> {} +unsafe impl<T: Send, A: Allocator + Send> Send for IntoIter<T, A> {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<T: Sync, A: AllocRef> Sync for IntoIter<T, A> {} +unsafe impl<T: Sync, A: Allocator> Sync for IntoIter<T, A> {} #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> Iterator for IntoIter<T, A> { +impl<T, A: Allocator> Iterator for IntoIter<T, A> { type Item = T; #[inline] @@ -3195,7 +3197,7 @@ impl<T, A: AllocRef> Iterator for IntoIter<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> DoubleEndedIterator for IntoIter<T, A> { +impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> { #[inline] fn next_back(&mut self) -> Option<T> { if self.end == self.ptr { @@ -3215,23 +3217,23 @@ impl<T, A: AllocRef> DoubleEndedIterator for IntoIter<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, A: AllocRef> ExactSizeIterator for IntoIter<T, A> { +impl<T, A: Allocator> ExactSizeIterator for IntoIter<T, A> { fn is_empty(&self) -> bool { self.ptr == self.end } } #[stable(feature = "fused", since = "1.26.0")] -impl<T, A: AllocRef> FusedIterator for IntoIter<T, A> {} +impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<T, A: AllocRef> TrustedLen for IntoIter<T, A> {} +unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] // T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr // and thus we can't implement drop-handling -unsafe impl<T, A: AllocRef> TrustedRandomAccess for IntoIter<T, A> +unsafe impl<T, A: Allocator> TrustedRandomAccess for IntoIter<T, A> where T: Copy, { @@ -3241,7 +3243,7 @@ where } #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl<T: Clone, A: AllocRef + Clone> Clone for IntoIter<T, A> { +impl<T: Clone, A: Allocator + Clone> Clone for IntoIter<T, A> { #[cfg(not(test))] fn clone(&self) -> Self { self.as_slice().to_vec_in(self.alloc.clone()).into_iter() @@ -3253,11 +3255,11 @@ impl<T: Clone, A: AllocRef + Clone> Clone for IntoIter<T, A> { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: AllocRef> Drop for IntoIter<T, A> { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter<T, A> { fn drop(&mut self) { - struct DropGuard<'a, T, A: AllocRef>(&'a mut IntoIter<T, A>); + struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter<T, A>); - impl<T, A: AllocRef> Drop for DropGuard<'_, T, A> { + impl<T, A: Allocator> Drop for DropGuard<'_, T, A> { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this @@ -3278,10 +3280,10 @@ unsafe impl<#[may_dangle] T, A: AllocRef> Drop for IntoIter<T, A> { } #[unstable(issue = "none", feature = "inplace_iteration")] -unsafe impl<T, A: AllocRef> InPlaceIterable for IntoIter<T, A> {} +unsafe impl<T, A: Allocator> InPlaceIterable for IntoIter<T, A> {} #[unstable(issue = "none", feature = "inplace_iteration")] -unsafe impl<T, A: AllocRef> SourceIter for IntoIter<T, A> { +unsafe impl<T, A: Allocator> SourceIter for IntoIter<T, A> { type Source = Self; #[inline] @@ -3320,7 +3322,7 @@ impl<T> AsIntoIter for IntoIter<T> { pub struct Drain< 'a, T: 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef + 'a = Global, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, > { /// Index of tail to preserve tail_start: usize, @@ -3332,13 +3334,13 @@ pub struct Drain< } #[stable(feature = "collection_debug", since = "1.17.0")] -impl<T: fmt::Debug, A: AllocRef> fmt::Debug for Drain<'_, T, A> { +impl<T: fmt::Debug, A: Allocator> fmt::Debug for Drain<'_, T, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } -impl<'a, T, A: AllocRef> Drain<'a, T, A> { +impl<'a, T, A: Allocator> Drain<'a, T, A> { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -3358,25 +3360,25 @@ impl<'a, T, A: AllocRef> Drain<'a, T, A> { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] #[inline] - pub fn alloc_ref(&self) -> &A { - unsafe { self.vec.as_ref().alloc_ref() } + pub fn allocator(&self) -> &A { + unsafe { self.vec.as_ref().allocator() } } } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] -impl<'a, T, A: AllocRef> AsRef<[T]> for Drain<'a, T, A> { +impl<'a, T, A: Allocator> AsRef<[T]> for Drain<'a, T, A> { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl<T: Sync, A: Sync + AllocRef> Sync for Drain<'_, T, A> {} +unsafe impl<T: Sync, A: Sync + Allocator> Sync for Drain<'_, T, A> {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl<T: Send, A: Send + AllocRef> Send for Drain<'_, T, A> {} +unsafe impl<T: Send, A: Send + Allocator> Send for Drain<'_, T, A> {} #[stable(feature = "drain", since = "1.6.0")] -impl<T, A: AllocRef> Iterator for Drain<'_, T, A> { +impl<T, A: Allocator> Iterator for Drain<'_, T, A> { type Item = T; #[inline] @@ -3390,7 +3392,7 @@ impl<T, A: AllocRef> Iterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl<T, A: AllocRef> DoubleEndedIterator for Drain<'_, T, A> { +impl<T, A: Allocator> DoubleEndedIterator for Drain<'_, T, A> { #[inline] fn next_back(&mut self) -> Option<T> { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -3398,13 +3400,13 @@ impl<T, A: AllocRef> DoubleEndedIterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl<T, A: AllocRef> Drop for Drain<'_, T, A> { +impl<T, A: Allocator> Drop for Drain<'_, T, A> { fn drop(&mut self) { /// Continues dropping the remaining elements in the `Drain`, then moves back the /// un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: AllocRef>(&'r mut Drain<'a, T, A>); + struct DropGuard<'r, 'a, T, A: Allocator>(&'r mut Drain<'a, T, A>); - impl<'r, 'a, T, A: AllocRef> Drop for DropGuard<'r, 'a, T, A> { + impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> { fn drop(&mut self) { // Continue the same loop we have below. If the loop already finished, this does // nothing. @@ -3440,17 +3442,17 @@ impl<T, A: AllocRef> Drop for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl<T, A: AllocRef> ExactSizeIterator for Drain<'_, T, A> { +impl<T, A: Allocator> ExactSizeIterator for Drain<'_, T, A> { fn is_empty(&self) -> bool { self.iter.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<T, A: AllocRef> TrustedLen for Drain<'_, T, A> {} +unsafe impl<T, A: Allocator> TrustedLen for Drain<'_, T, A> {} #[stable(feature = "fused", since = "1.26.0")] -impl<T, A: AllocRef> FusedIterator for Drain<'_, T, A> {} +impl<T, A: Allocator> FusedIterator for Drain<'_, T, A> {} /// A splicing iterator for `Vec`. /// @@ -3469,14 +3471,14 @@ impl<T, A: AllocRef> FusedIterator for Drain<'_, T, A> {} pub struct Splice< 'a, I: Iterator + 'a, - #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef + 'a = Global, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, > { drain: Drain<'a, I::Item, A>, replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<I: Iterator, A: AllocRef> Iterator for Splice<'_, I, A> { +impl<I: Iterator, A: Allocator> Iterator for Splice<'_, I, A> { type Item = I::Item; fn next(&mut self) -> Option<Self::Item> { @@ -3489,17 +3491,17 @@ impl<I: Iterator, A: AllocRef> Iterator for Splice<'_, I, A> { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<I: Iterator, A: AllocRef> DoubleEndedIterator for Splice<'_, I, A> { +impl<I: Iterator, A: Allocator> DoubleEndedIterator for Splice<'_, I, A> { fn next_back(&mut self) -> Option<Self::Item> { self.drain.next_back() } } #[stable(feature = "vec_splice", since = "1.21.0")] -impl<I: Iterator, A: AllocRef> ExactSizeIterator for Splice<'_, I, A> {} +impl<I: Iterator, A: Allocator> ExactSizeIterator for Splice<'_, I, A> {} #[stable(feature = "vec_splice", since = "1.21.0")] -impl<I: Iterator, A: AllocRef> Drop for Splice<'_, I, A> { +impl<I: Iterator, A: Allocator> Drop for Splice<'_, I, A> { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -3540,7 +3542,7 @@ impl<I: Iterator, A: AllocRef> Drop for Splice<'_, I, A> { } /// Private helper methods for `Splice::drop` -impl<T, A: AllocRef> Drain<'_, T, A> { +impl<T, A: Allocator> Drain<'_, T, A> { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. @@ -3599,7 +3601,7 @@ pub struct DrainFilter< 'a, T, F, - #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, > where F: FnMut(&mut T) -> bool, { @@ -3620,20 +3622,20 @@ pub struct DrainFilter< panic_flag: bool, } -impl<T, F, A: AllocRef> DrainFilter<'_, T, F, A> +impl<T, F, A: Allocator> DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] #[inline] - pub fn alloc_ref(&self) -> &A { - self.vec.alloc_ref() + pub fn allocator(&self) -> &A { + self.vec.allocator() } } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<T, F, A: AllocRef> Iterator for DrainFilter<'_, T, F, A> +impl<T, F, A: Allocator> Iterator for DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, { @@ -3671,19 +3673,19 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<T, F, A: AllocRef> Drop for DrainFilter<'_, T, F, A> +impl<T, F, A: Allocator> Drop for DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, { fn drop(&mut self) { - struct BackshiftOnDrop<'a, 'b, T, F, A: AllocRef> + struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator> where F: FnMut(&mut T) -> bool, { drain: &'b mut DrainFilter<'a, T, F, A>, } - impl<'a, 'b, T, F, A: AllocRef> Drop for BackshiftOnDrop<'a, 'b, T, F, A> + impl<'a, 'b, T, F, A: Allocator> Drop for BackshiftOnDrop<'a, 'b, T, F, A> where F: FnMut(&mut T) -> bool, { |
