Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnay
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
This commit is contained in:
commit
ad981d58e1
9 changed files with 8 additions and 16 deletions
|
@ -973,7 +973,6 @@ impl<T> BinaryHeap<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::BinaryHeap;
|
||||
/// let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
|
||||
///
|
||||
|
@ -982,7 +981,7 @@ impl<T> BinaryHeap<T> {
|
|||
/// assert!(heap.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.data.shrink_to(min_capacity)
|
||||
}
|
||||
|
|
|
@ -816,7 +816,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::VecDeque;
|
||||
///
|
||||
/// let mut buf = VecDeque::with_capacity(15);
|
||||
|
@ -827,7 +826,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
|||
/// buf.shrink_to(0);
|
||||
/// assert!(buf.capacity() >= 4);
|
||||
/// ```
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
let min_capacity = cmp::min(min_capacity, self.capacity());
|
||||
// We don't have to worry about an overflow as neither `self.len()` nor `self.capacity()`
|
||||
|
|
|
@ -1100,7 +1100,6 @@ impl String {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// let mut s = String::from("foo");
|
||||
///
|
||||
/// s.reserve(100);
|
||||
|
@ -1113,7 +1112,7 @@ impl String {
|
|||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.vec.shrink_to(min_capacity)
|
||||
}
|
||||
|
|
|
@ -947,7 +947,6 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.extend([1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
|
@ -957,7 +956,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
/// assert!(vec.capacity() >= 3);
|
||||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
if self.capacity() > min_capacity {
|
||||
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));
|
||||
|
|
|
@ -667,7 +667,6 @@ where
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
|
||||
|
@ -680,7 +679,7 @@ where
|
|||
/// assert!(map.capacity() >= 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.base.shrink_to(min_capacity);
|
||||
}
|
||||
|
|
|
@ -464,7 +464,6 @@ where
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::HashSet;
|
||||
///
|
||||
/// let mut set = HashSet::with_capacity(100);
|
||||
|
@ -477,7 +476,7 @@ where
|
|||
/// assert!(set.capacity() >= 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.base.shrink_to(min_capacity)
|
||||
}
|
||||
|
|
|
@ -321,7 +321,6 @@ impl OsString {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::ffi::OsString;
|
||||
///
|
||||
/// let mut s = OsString::from("foo");
|
||||
|
@ -335,7 +334,7 @@ impl OsString {
|
|||
/// assert!(s.capacity() >= 3);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.inner.shrink_to(min_capacity)
|
||||
}
|
||||
|
|
|
@ -308,7 +308,6 @@
|
|||
#![feature(ptr_internals)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(shrink_to)]
|
||||
#![feature(slice_concat_ext)]
|
||||
#![feature(slice_internals)]
|
||||
#![feature(slice_ptr_get)]
|
||||
|
|
|
@ -1398,7 +1398,7 @@ impl PathBuf {
|
|||
/// Invokes [`shrink_to`] on the underlying instance of [`OsString`].
|
||||
///
|
||||
/// [`shrink_to`]: OsString::shrink_to
|
||||
#[unstable(feature = "shrink_to", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.56.0")]
|
||||
#[inline]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.inner.shrink_to(min_capacity)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue