Auto merge of #81335 - thomwiggers:no-panic-shrink-to, r=Mark-Simulacrum
Trying to shrink_to greater than capacity should be no-op Per the discussion in https://github.com/rust-lang/rust/issues/56431, `shrink_to` shouldn't panic if you try to make a vector shrink to a capacity greater than its current capacity.
This commit is contained in:
commit
a2f8f62818
8 changed files with 15 additions and 32 deletions
|
@ -658,8 +658,7 @@ where
|
|||
/// down no lower than the supplied limit while maintaining the internal rules
|
||||
/// and possibly leaving some space in accordance with the resize policy.
|
||||
///
|
||||
/// Panics if the current capacity is smaller than the supplied
|
||||
/// minimum capacity.
|
||||
/// If the current capacity is less than the lower limit, this is a no-op.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -679,7 +678,6 @@ where
|
|||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
assert!(self.capacity() >= min_capacity, "Tried to shrink to a larger capacity");
|
||||
self.base.shrink_to(min_capacity);
|
||||
}
|
||||
|
||||
|
|
|
@ -462,9 +462,7 @@ where
|
|||
/// down no lower than the supplied limit while maintaining the internal rules
|
||||
/// and possibly leaving some space in accordance with the resize policy.
|
||||
///
|
||||
/// Panics if the current capacity is smaller than the supplied
|
||||
/// minimum capacity.
|
||||
///
|
||||
/// If the current capacity is less than the lower limit, this is a no-op.
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
|
|
@ -304,8 +304,7 @@ impl OsString {
|
|||
/// The capacity will remain at least as large as both the length
|
||||
/// and the supplied value.
|
||||
///
|
||||
/// Panics if the current capacity is smaller than the supplied
|
||||
/// minimum capacity.
|
||||
/// If the current capacity is less than the lower limit, this is a no-op.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue