]> git.lizzy.rs Git - rust.git/commitdiff
Guarantee `try_reserve` preserves the contents on error
authorYOSHIOKA Takuma <nop_thread@nops.red>
Tue, 9 Aug 2022 16:51:38 +0000 (01:51 +0900)
committerYOSHIOKA Takuma <nop_thread@nops.red>
Tue, 9 Aug 2022 16:51:38 +0000 (01:51 +0900)
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.

library/alloc/src/collections/binary_heap.rs
library/alloc/src/collections/vec_deque/mod.rs
library/alloc/src/string.rs
library/alloc/src/vec/mod.rs
library/std/src/ffi/os_str.rs
library/std/src/sys_common/wtf8.rs

index 197e7aaaccf3d34d59d180582ee54426ef6c0e1b..4583bc9a158efc02c059e239c40962faf529f9ce 100644 (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
     ///
index 4d895d83745b219951368e91196794cc97cdd249..41b6b6e4f528861f1adf0f35e2b42119a4803f3c 100644 (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
     ///
index a5118e5333b825776e36a84ecb0b44f4f2523d3a..dce0beb4fe730d8dd9508f1705d4d2269a81bd23 100644 (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
     ///
index fa9f2131c0c1d3e2db6896e9925677d1692507e2..27027fa3a6fad8da5b526629b91697df5ca09e90 100644 (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
     ///
index a0a5c003d281ad394403ebb1b5d1e74e33beb920..80ed34157e6dcd24b221c81a9dd50a12827dc892 100644 (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.
     ///
index 57fa4989358a4f5d880aa142a6dcfdf907693610..33e20756163fd8761989eb9cf209053909575ed5 100644 (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
     ///