Skip to content

Commit 774d082

Browse files
authored
Unrolled build for #148662
Rollup merge of #148662 - leftmostcat:document-isize-limit, r=joboet alloc: Document panics when allocations will exceed max Document panics in `String` and `Vec` due to capacity overflowing `isize::MAX`. Correct outdated claims of `usize::MAX` limit. Fixes #148598. Ping `@lolbinarycat`
2 parents 97b131c + 5a8cf33 commit 774d082

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

library/alloc/src/string.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ impl String {
454454
///
455455
/// [`new`]: String::new
456456
///
457+
/// # Panics
458+
///
459+
/// Panics if the capacity exceeds `isize::MAX` _bytes_.
460+
///
457461
/// # Examples
458462
///
459463
/// ```
@@ -1079,6 +1083,10 @@ impl String {
10791083

10801084
/// Appends a given string slice onto the end of this `String`.
10811085
///
1086+
/// # Panics
1087+
///
1088+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
1089+
///
10821090
/// # Examples
10831091
///
10841092
/// ```
@@ -1101,8 +1109,9 @@ impl String {
11011109
///
11021110
/// # Panics
11031111
///
1104-
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1105-
/// bounded on either end and does not lie on a [`char`] boundary.
1112+
/// Panics if the range has `start_bound > end_bound`, if the range is
1113+
/// bounded on either end and does not lie on a [`char`] boundary, or if the
1114+
/// new capacity exceeds `isize::MAX` bytes.
11061115
///
11071116
/// # Examples
11081117
///
@@ -1158,7 +1167,7 @@ impl String {
11581167
///
11591168
/// # Panics
11601169
///
1161-
/// Panics if the new capacity overflows [`usize`].
1170+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
11621171
///
11631172
/// # Examples
11641173
///
@@ -1208,7 +1217,7 @@ impl String {
12081217
///
12091218
/// # Panics
12101219
///
1211-
/// Panics if the new capacity overflows [`usize`].
1220+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
12121221
///
12131222
/// # Examples
12141223
///
@@ -1372,6 +1381,10 @@ impl String {
13721381

13731382
/// Appends the given [`char`] to the end of this `String`.
13741383
///
1384+
/// # Panics
1385+
///
1386+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
1387+
///
13751388
/// # Examples
13761389
///
13771390
/// ```

library/alloc/src/vec/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,6 +3340,10 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
33403340
/// except that it also works with slice elements that are Clone but not Copy.
33413341
/// If Rust gets specialization this function may be deprecated.
33423342
///
3343+
/// # Panics
3344+
///
3345+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
3346+
///
33433347
/// # Examples
33443348
///
33453349
/// ```
@@ -3361,8 +3365,9 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
33613365
///
33623366
/// # Panics
33633367
///
3364-
/// Panics if starting index is greater than the end index
3365-
/// or if the index is greater than the length of the vector.
3368+
/// Panics if starting index is greater than the end index, if the index is
3369+
/// greater than the length of the vector, or if the new capacity exceeds
3370+
/// `isize::MAX` _bytes_.
33663371
///
33673372
/// # Examples
33683373
///

0 commit comments

Comments
 (0)