Guarantee try_reserve preserves the contents on error

Update doc comments to make the guarantee explicit. However, some
implementations does not have the statement though.

* `HashMap`, `HashSet`: require guarantees on hashbrown side.
* `PathBuf`: simply redirecting to `OsString`.

Fixes #99606.
This commit is contained in:
YOSHIOKA Takuma 2022-08-10 01:51:38 +09:00
parent cc4dd6fc9f
commit 2bb7e1e6ed
No known key found for this signature in database
GPG Key ID: EF2059A2B64518D7
6 changed files with 12 additions and 6 deletions

View File

@ -1010,7 +1010,8 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
/// preserves the contents even if an error occurs.
///
/// # Errors
///

View File

@ -794,7 +794,8 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
/// in the given deque. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
/// preserves the contents even if an error occurs.
///
/// # Errors
///

View File

@ -1080,7 +1080,8 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// current length. The allocator may reserve more space to speculatively
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
/// preserves the contents even if an error occurs.
///
/// # Errors
///

View File

@ -875,7 +875,8 @@ pub fn reserve_exact(&mut self, additional: usize) {
/// in the given `Vec<T>`. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns
/// `Ok(())`. Does nothing if capacity is already sufficient.
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
/// preserves the contents even if an error occurs.
///
/// # Errors
///

View File

@ -290,7 +290,8 @@ pub fn reserve(&mut self, additional: usize) {
/// in the given `OsString`. The string may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if capacity is already sufficient.
/// Does nothing if capacity is already sufficient. This method preserves
/// the contents even if an error occurs.
///
/// See the main `OsString` documentation information about encoding and capacity units.
///

View File

@ -236,7 +236,8 @@ pub fn reserve(&mut self, additional: usize) {
/// in the given `Wtf8Buf`. The `Wtf8Buf` may reserve more space to avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
/// capacity is already sufficient. This method preserves the contents even
/// if an error occurs.
///
/// # Errors
///