Skip to content

Commit

Permalink
Make it clearer what String::leak is useful for
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo authored May 18, 2024
1 parent 685a80f commit e5269fc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,9 @@ impl String {

/// Converts this `String` into a <code>[Box]<[str]></code>.
///
/// This will drop any excess capacity.
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
///
/// [`shrink_to_fit`]: String::shrink_to_fit
/// [str]: prim@str "str"
///
/// # Examples
Expand Down Expand Up @@ -1969,8 +1970,11 @@ impl String {
///
/// It does not reallocate or shrink the `String`,
/// so the leaked allocation may include unused capacity that is not part
/// of the returned slice. If you don't want that, call [`into_boxed_str`],
/// and then [`Box::leak`].
/// of the returned slice. The advantage of this is that it avoids the potential
/// reallocation that [`shrink_to_fit`] may perform.
///

Check failure on line 1975 in library/alloc/src/string.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

trailing whitespace
/// If you want to discard excess capacity, call [`into_boxed_str`],
/// and then [`Box::leak`] instead.
///
/// [`into_boxed_str`]: Self::into_boxed_str
///
Expand Down

0 comments on commit e5269fc

Please sign in to comment.