Skip to content

Commit ad981d5

Browse files
committed
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.
2 parents 442e627 + 8ec5060 commit ad981d5

File tree

9 files changed

+8
-16
lines changed

9 files changed

+8
-16
lines changed

library/alloc/src/collections/binary_heap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,6 @@ impl<T> BinaryHeap<T> {
973973
/// # Examples
974974
///
975975
/// ```
976-
/// #![feature(shrink_to)]
977976
/// use std::collections::BinaryHeap;
978977
/// let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
979978
///
@@ -982,7 +981,7 @@ impl<T> BinaryHeap<T> {
982981
/// assert!(heap.capacity() >= 10);
983982
/// ```
984983
#[inline]
985-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
984+
#[stable(feature = "shrink_to", since = "1.56.0")]
986985
pub fn shrink_to(&mut self, min_capacity: usize) {
987986
self.data.shrink_to(min_capacity)
988987
}

library/alloc/src/collections/vec_deque/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
816816
/// # Examples
817817
///
818818
/// ```
819-
/// #![feature(shrink_to)]
820819
/// use std::collections::VecDeque;
821820
///
822821
/// let mut buf = VecDeque::with_capacity(15);
@@ -827,7 +826,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
827826
/// buf.shrink_to(0);
828827
/// assert!(buf.capacity() >= 4);
829828
/// ```
830-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
829+
#[stable(feature = "shrink_to", since = "1.56.0")]
831830
pub fn shrink_to(&mut self, min_capacity: usize) {
832831
let min_capacity = cmp::min(min_capacity, self.capacity());
833832
// We don't have to worry about an overflow as neither `self.len()` nor `self.capacity()`

library/alloc/src/string.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,6 @@ impl String {
11001100
/// # Examples
11011101
///
11021102
/// ```
1103-
/// #![feature(shrink_to)]
11041103
/// let mut s = String::from("foo");
11051104
///
11061105
/// s.reserve(100);
@@ -1113,7 +1112,7 @@ impl String {
11131112
/// ```
11141113
#[cfg(not(no_global_oom_handling))]
11151114
#[inline]
1116-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
1115+
#[stable(feature = "shrink_to", since = "1.56.0")]
11171116
pub fn shrink_to(&mut self, min_capacity: usize) {
11181117
self.vec.shrink_to(min_capacity)
11191118
}

library/alloc/src/vec/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,6 @@ impl<T, A: Allocator> Vec<T, A> {
947947
/// # Examples
948948
///
949949
/// ```
950-
/// #![feature(shrink_to)]
951950
/// let mut vec = Vec::with_capacity(10);
952951
/// vec.extend([1, 2, 3]);
953952
/// assert_eq!(vec.capacity(), 10);
@@ -957,7 +956,7 @@ impl<T, A: Allocator> Vec<T, A> {
957956
/// assert!(vec.capacity() >= 3);
958957
/// ```
959958
#[cfg(not(no_global_oom_handling))]
960-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
959+
#[stable(feature = "shrink_to", since = "1.56.0")]
961960
pub fn shrink_to(&mut self, min_capacity: usize) {
962961
if self.capacity() > min_capacity {
963962
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));

library/std/src/collections/hash/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ where
667667
/// # Examples
668668
///
669669
/// ```
670-
/// #![feature(shrink_to)]
671670
/// use std::collections::HashMap;
672671
///
673672
/// let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
@@ -680,7 +679,7 @@ where
680679
/// assert!(map.capacity() >= 2);
681680
/// ```
682681
#[inline]
683-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
682+
#[stable(feature = "shrink_to", since = "1.56.0")]
684683
pub fn shrink_to(&mut self, min_capacity: usize) {
685684
self.base.shrink_to(min_capacity);
686685
}

library/std/src/collections/hash/set.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ where
464464
/// # Examples
465465
///
466466
/// ```
467-
/// #![feature(shrink_to)]
468467
/// use std::collections::HashSet;
469468
///
470469
/// let mut set = HashSet::with_capacity(100);
@@ -477,7 +476,7 @@ where
477476
/// assert!(set.capacity() >= 2);
478477
/// ```
479478
#[inline]
480-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
479+
#[stable(feature = "shrink_to", since = "1.56.0")]
481480
pub fn shrink_to(&mut self, min_capacity: usize) {
482481
self.base.shrink_to(min_capacity)
483482
}

library/std/src/ffi/os_str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ impl OsString {
321321
/// # Examples
322322
///
323323
/// ```
324-
/// #![feature(shrink_to)]
325324
/// use std::ffi::OsString;
326325
///
327326
/// let mut s = OsString::from("foo");
@@ -335,7 +334,7 @@ impl OsString {
335334
/// assert!(s.capacity() >= 3);
336335
/// ```
337336
#[inline]
338-
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
337+
#[stable(feature = "shrink_to", since = "1.56.0")]
339338
pub fn shrink_to(&mut self, min_capacity: usize) {
340339
self.inner.shrink_to(min_capacity)
341340
}

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@
308308
#![feature(ptr_internals)]
309309
#![feature(rustc_attrs)]
310310
#![feature(rustc_private)]
311-
#![feature(shrink_to)]
312311
#![feature(slice_concat_ext)]
313312
#![feature(slice_internals)]
314313
#![feature(slice_ptr_get)]

library/std/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ impl PathBuf {
13981398
/// Invokes [`shrink_to`] on the underlying instance of [`OsString`].
13991399
///
14001400
/// [`shrink_to`]: OsString::shrink_to
1401-
#[unstable(feature = "shrink_to", issue = "56431")]
1401+
#[stable(feature = "shrink_to", since = "1.56.0")]
14021402
#[inline]
14031403
pub fn shrink_to(&mut self, min_capacity: usize) {
14041404
self.inner.shrink_to(min_capacity)

0 commit comments

Comments
 (0)