Skip to content

Commit 2bb7e1e

Browse files
committed
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.
1 parent cc4dd6f commit 2bb7e1e

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

library/alloc/src/collections/binary_heap.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ impl<T> BinaryHeap<T> {
10101010
/// current length. The allocator may reserve more space to speculatively
10111011
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
10121012
/// greater than or equal to `self.len() + additional` if it returns
1013-
/// `Ok(())`. Does nothing if capacity is already sufficient.
1013+
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
1014+
/// preserves the contents even if an error occurs.
10141015
///
10151016
/// # Errors
10161017
///

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
794794
/// in the given deque. The collection may reserve more space to speculatively avoid
795795
/// frequent reallocations. After calling `try_reserve`, capacity will be
796796
/// greater than or equal to `self.len() + additional` if it returns
797-
/// `Ok(())`. Does nothing if capacity is already sufficient.
797+
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
798+
/// preserves the contents even if an error occurs.
798799
///
799800
/// # Errors
800801
///

library/alloc/src/string.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ impl String {
10801080
/// current length. The allocator may reserve more space to speculatively
10811081
/// avoid frequent allocations. After calling `try_reserve`, capacity will be
10821082
/// greater than or equal to `self.len() + additional` if it returns
1083-
/// `Ok(())`. Does nothing if capacity is already sufficient.
1083+
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
1084+
/// preserves the contents even if an error occurs.
10841085
///
10851086
/// # Errors
10861087
///

library/alloc/src/vec/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ impl<T, A: Allocator> Vec<T, A> {
875875
/// in the given `Vec<T>`. The collection may reserve more space to speculatively avoid
876876
/// frequent reallocations. After calling `try_reserve`, capacity will be
877877
/// greater than or equal to `self.len() + additional` if it returns
878-
/// `Ok(())`. Does nothing if capacity is already sufficient.
878+
/// `Ok(())`. Does nothing if capacity is already sufficient. This method
879+
/// preserves the contents even if an error occurs.
879880
///
880881
/// # Errors
881882
///

library/std/src/ffi/os_str.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ impl OsString {
290290
/// in the given `OsString`. The string may reserve more space to speculatively avoid
291291
/// frequent reallocations. After calling `try_reserve`, capacity will be
292292
/// greater than or equal to `self.len() + additional` if it returns `Ok(())`.
293-
/// Does nothing if capacity is already sufficient.
293+
/// Does nothing if capacity is already sufficient. This method preserves
294+
/// the contents even if an error occurs.
294295
///
295296
/// See the main `OsString` documentation information about encoding and capacity units.
296297
///

library/std/src/sys_common/wtf8.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ impl Wtf8Buf {
236236
/// in the given `Wtf8Buf`. The `Wtf8Buf` may reserve more space to avoid
237237
/// frequent reallocations. After calling `try_reserve`, capacity will be
238238
/// greater than or equal to `self.len() + additional`. Does nothing if
239-
/// capacity is already sufficient.
239+
/// capacity is already sufficient. This method preserves the contents even
240+
/// if an error occurs.
240241
///
241242
/// # Errors
242243
///

0 commit comments

Comments
 (0)