@@ -1941,6 +1941,7 @@ impl String {
1941
1941
/// Converts this `String` into a <code>[Box]<[str]></code>.
1942
1942
///
1943
1943
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
1944
+ /// Note that the [`shrink_to_fit`] call may reallocate and copy the bytes of the string.
1944
1945
///
1945
1946
/// [`shrink_to_fit`]: String::shrink_to_fit
1946
1947
/// [str]: prim@str "str"
@@ -1968,13 +1969,10 @@ impl String {
1968
1969
/// this function is ideally used for data that lives for the remainder of the program's life,
1969
1970
/// as dropping the returned reference will cause a memory leak.
1970
1971
///
1971
- /// It does not reallocate or shrink the `String`,
1972
- /// so the leaked allocation may include unused capacity that is not part
1973
- /// of the returned slice. The advantage of this is that it avoids the potential
1974
- /// reallocation that [`shrink_to_fit`] may perform.
1975
- ///
1976
- /// If you want to discard excess capacity, call [`into_boxed_str`],
1977
- /// and then [`Box::leak`] instead.
1972
+ /// It does not reallocate or shrink the `String`, so the leaked allocation may include unused
1973
+ /// capacity that is not part of the returned slice. If you want to discard excess capacity,
1974
+ /// call [`into_boxed_str`], and then [`Box::leak`] instead. However, keep in mind that
1975
+ /// trimming the capacity may result in a reallocation and copy.
1978
1976
///
1979
1977
/// [`into_boxed_str`]: Self::into_boxed_str
1980
1978
///
0 commit comments