Skip to content

Commit 3ab0d90

Browse files
committed
Stabilize String::leak
1 parent ddad057 commit 3ab0d90

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

library/alloc/src/string.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,26 +1853,27 @@ impl String {
18531853
/// Consumes and leaks the `String`, returning a mutable reference to the contents,
18541854
/// `&'a mut str`.
18551855
///
1856-
/// This is mainly useful for data that lives for the remainder of
1857-
/// the program's life. Dropping the returned reference will cause a memory
1858-
/// leak.
1856+
/// The caller has free choice over the returned lifetime, including `'static`. Indeed,
1857+
/// this function is ideally used for data that lives for the remainder of the program's life,
1858+
/// as dropping the returned reference will cause a memory leak.
18591859
///
18601860
/// It does not reallocate or shrink the `String`,
18611861
/// so the leaked allocation may include unused capacity that is not part
1862-
/// of the returned slice.
1862+
/// of the returned slice. If you don't want that, call [`into_boxed_str`],
1863+
/// and then [`Box::leak`].
1864+
///
1865+
/// [`into_boxed_str`]: Self::into_boxed_str
18631866
///
18641867
/// # Examples
18651868
///
18661869
/// Simple usage:
18671870
///
18681871
/// ```
1869-
/// #![feature(string_leak)]
1870-
///
18711872
/// let x = String::from("bucket");
18721873
/// let static_ref: &'static mut str = x.leak();
18731874
/// assert_eq!(static_ref, "bucket");
18741875
/// ```
1875-
#[unstable(feature = "string_leak", issue = "102929")]
1876+
#[stable(feature = "string_leak", since = "CURRENT_RUSTC_VERSION")]
18761877
#[inline]
18771878
pub fn leak<'a>(self) -> &'a mut str {
18781879
let slice = self.vec.leak();

0 commit comments

Comments
 (0)