Skip to content

Commit 7528a5b

Browse files
author
Seán de Búrca
committed
alloc: Document panics when allocations will exceed max
1 parent 843f8ce commit 7528a5b

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
@@ -461,6 +461,10 @@ impl String {
461461
///
462462
/// [`new`]: String::new
463463
///
464+
/// # Panics
465+
///
466+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
467+
///
464468
/// # Examples
465469
///
466470
/// ```
@@ -1094,6 +1098,10 @@ impl String {
10941098

10951099
/// Appends a given string slice onto the end of this `String`.
10961100
///
1101+
/// # Panics
1102+
///
1103+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
1104+
///
10971105
/// # Examples
10981106
///
10991107
/// ```
@@ -1116,8 +1124,9 @@ impl String {
11161124
///
11171125
/// # Panics
11181126
///
1119-
/// Panics if the range has `start_bound > end_bound`, or, if the range is
1120-
/// bounded on either end and does not lie on a [`char`] boundary.
1127+
/// Panics if the range has `start_bound > end_bound`, if the range is
1128+
/// bounded on either end and does not lie on a [`char`] boundary, or if the
1129+
/// new capacity exceeds `isize::MAX` bytes.
11211130
///
11221131
/// # Examples
11231132
///
@@ -1173,7 +1182,7 @@ impl String {
11731182
///
11741183
/// # Panics
11751184
///
1176-
/// Panics if the new capacity overflows [`usize`].
1185+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
11771186
///
11781187
/// # Examples
11791188
///
@@ -1223,7 +1232,7 @@ impl String {
12231232
///
12241233
/// # Panics
12251234
///
1226-
/// Panics if the new capacity overflows [`usize`].
1235+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
12271236
///
12281237
/// # Examples
12291238
///
@@ -1387,6 +1396,10 @@ impl String {
13871396

13881397
/// Appends the given [`char`] to the end of this `String`.
13891398
///
1399+
/// # Panics
1400+
///
1401+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
1402+
///
13901403
/// # Examples
13911404
///
13921405
/// ```

library/alloc/src/vec/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,10 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
32923292
/// except that it also works with slice elements that are Clone but not Copy.
32933293
/// If Rust gets specialization this function may be deprecated.
32943294
///
3295+
/// # Panics
3296+
///
3297+
/// Panics if the new capacity exceeds `isize::MAX` _bytes_.
3298+
///
32953299
/// # Examples
32963300
///
32973301
/// ```
@@ -3313,8 +3317,9 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
33133317
///
33143318
/// # Panics
33153319
///
3316-
/// Panics if starting index is greater than the end index
3317-
/// or if the index is greater than the length of the vector.
3320+
/// Panics if starting index is greater than the end index, if the index is
3321+
/// greater than the length of the vector, or if the new capacity exceeds
3322+
/// `isize::MAX` _bytes_.
33183323
///
33193324
/// # Examples
33203325
///

0 commit comments

Comments
 (0)