Skip to content

Commit b8f71ea

Browse files
authored
Rollup merge of #109814 - est31:stabilize_string_leak, r=Amanieu
Stabilize String::leak Stabilizes the following API: ```Rust impl String { pub fn leak(self) -> &'static mut str; } ``` closes #102929 blocked by having an FCP for stabilization.
2 parents d54bb50 + 3ab0d90 commit b8f71ea

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

library/alloc/src/string.rs

+8-7
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)